Select command

The syntax of the select command is

select name [ in word ... ]

do list

done

The words are expanded, generating a list of items. If word is not specified, the positional parameters are expanded. The set of expanded words is written to standard error, each preceded by a number. The PS3 prompt is then displayed and a line is read from standard input. If the line consists of a number corresponding to one of the displayed words, qsh sets the value of name to the word corresponding to the number. If the line is empty, qsh displays the list again. The REPLY variable is set to the contents of the input line.

qsh runs the commands in list until a break, return, or exit command is run. select also completes if EOF is read from standard input.

Examples

  1. A select command to select from a list.
    PS3="Please select a number "
    list="alpha beta gamma delta epsilon"
    select value in $list ; do
      echo Value for selection $REPLY is $value
      break
    done