JamesPoppycock JamesPoppycock - 1 year ago 49
Bash Question

Bash select statement with Alphabets as options

I am currently coding a menu using the select statement as shown below.

options=("Say Hello" "Say Bye" "Say Go Away")
select alphabets in "${options}";
case $REPLY in
a) echo Hello ;;
b) echo Bye ;;
c) echo GoAway; break;;

I want the output to show:

a) Say Hello
b) Say Bye
c) Say Go away

but the output shows numerical numbers as shown below:

1) Say Hello
2) Say Bye
3) Say Go away

Is there anyway for me to make it such that I get alphabets as the options?
Thank you!

Answer Source

Judging by this:

$ help select
select: select NAME [in WORDS ... ;] do COMMANDS; done
    The WORDS are expanded, generating a list of words.  The
    set of expanded words is printed on the standard error, each
    preceded by a number.  [...]

I'm afraid what you want is not possible. The choices will be numbered, and this behavior is not configurable to make it alphabetic.

If you want to see alphabetic options, you have to implement your own.