Well, even some less-experienced bash
users would know meanwhile about the fact that bash
arrays would always start with index 0.
However, select
will always do its own thing, as the following example shows:
#!/bin/bash
choices=(NONE nyc la chicago little_rock miami)
select choice in ${choices[@]}; do
[[ " ${choices[*]} " == *" $choice "* ]] && break
done
echo "Choice was: $choice ; first element is ${choices[0]}"
Output is:
1) NONE
2) nyc
... etc. ...
BUT ${choices[0]}
will output 'NONE' nonetheless!
So I feel that somehow there must be a way to force select
to start with index 0, not 1.
(Should anyone question the deeper sense of this: there actually is, especially when you have to skip processing frequently (ideally set as '0' in the menu) with more than 9 options and, for convenience's sake, you would put the least-used option as '10' so you may only have to type a single digit in almost every case.)