Bash Shell Process Control--select

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.