Time to give our client a menu
In this chapter, we are looking at different to play with loops in order to work on the pieces of information the user provides us with. From a simple menu, we moved onto something fancier and better looking; and now, it is time to take a step further and have a look at the select
construct whose task is to let us create menu in an effortless way. Its syntax is similar to the for construct:
select placeholder [in list] do command_1 command_2 command_n done
So, as we can see, this construct is very similar to for
and sports a list, which gets expanded on the standard error in a series of elements preceded by a number. If we omit the in list
part, the list gets constructed from the positional parameters given on the command line, such as if we used [in $@]
. Once the elements in the list are printed, a PS3
prompt is shown and a line from the stdin
is read and stored into the REPLY variable. If something is read on the line, each word is displayed along with a number...