Preface today just wrote an automated packaging script, again using the bash shell, a good feeling of happiness. The main point here is to introduce the Select command, which can help us to complete the menu selection function.
Format I am also the first to use Select Process Control, in PHP, Java, C these languages do not implement the Select function. In the Bash shell, the Select format is as follows:
Select $var in ${list[@]}do statements the can use $vardone
When select executes, the selection menu is given based on the list array, the user-selected results are saved in the $var variable, and then the statements statement is executed. After execution, give the menu again and wait for the user to select it. If the user wants to jump out of the selection loop, the break statement needs to be added to the loop body in terms of conditions.
Example gives an example of a select, which you can refer to:
#!/bin/bashfruits= ( "apple" "pear" "orange" "watermelon") echo "please guess which fruit I like:" Select Var in ${fruits[@]}do if [$var = "Apple"] and then echo "Congratulations, your is my good firend!" Break Else echo "Try again!" Fidone
Bash Shell Process Control--select