Almost all of the flow-control constructs we have seen so far are also
available in the Bourne shell, and the C shell has equivalents with
different syntax. Our next construct,
select, is unique to the Korn shell;
moreover, it has no analogue in conventional programming languages.
select allows you to generate simple menus easily.
It has concise syntax, but it does quite a lot of work.
The syntax is:
statements that can use$name ... done
This is the same syntax as the regular
for loop except for
for, you can omit
it will default to
the list of quoted command-line arguments.
Here is what
Generates a menu of each item in list, formatted with numbers for each choice
Prompts the user for a number (with the value of
Stores the selected choice in the variable name
and the selected number in the built-in variable
Executes the statements in the body
Repeats the process forever (but see below for how to exit)
Once again, an example should help make this process clearer. Assume you need to write the code for Task 5-4, but your life is not as simple. You don’t have terminals hardwired to your computer; instead, your users communicate through a terminal server, or they log in remotely, via telnet or ssh. This means, among other things, that the tty number does not determine the type of terminal.
Therefore, you have no choice but to prompt the user for his or her terminal ...