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. If `in WORDS' is not present, `in "$@"'
is assumed. The PS3 prompt is then displayed and a line read
from the standard input. If the line consists of the number
corresponding to one of the displayed words, then NAME is set
to that word. If the line is empty, WORDS and the prompt are
redisplayed. If EOF is read, the command completes. Any other
value read causes NAME to be set to null. The line read is saved
in the variable REPLY. COMMANDS are executed after each selection
until a break or return command is executed.
that's "help select", heh, dunno bout you people, it doesn't "help" me much at all
What the above so "eloquently" tries to inform you of is that select is very handy to make numbered menu's and so forth (basically).
#!/bin/bash
#uses select to make a menu (remember to set PS3 to something)
PS3="Make a Selection? "
LIST="test me now rocksteady quit"
select NONO in $LIST
do
echo -e "from\n $LIST\n you picked $NONO"
if test "$NONO" = "quit"
then
return 0
fi
done
| Bash scripting 101: Chapter 8: dare you risk some misc? |