Select is also a kind of loop, it is more suitable for use in the case of user choice.
For example, we have one such requirement, after running the script, let the user go to select the number and then execute the command!
#!/bin/bashselect Mysql_v in 5.1 5.6docase $mysql _v in5.1) echo "You choose the 5.1" #break /break This line has been commented out;; 5.6) echo "You choose the 5.6" #break/break This line is commented out;; Esacdone
Then execute this script
[[Email protected] sbin]# sh 3.sh1) 5.12) 5.6#? 1you Choose the 5.1#? 2you Choose the 5.6#? 1you Choose the 5.1#? 1you Choose the 5.1#? 2you Choose the 5.6#? 2you Choose the 5.6#? /will find that as long as the choice will continue to carry out, and will not quit!
Add a break line to the script:
#!/bin/bashselect Mysql_v in 5.1 5.6docase $mysql _v in5.1) echo "You choose the 5.1" Break/bre AK was not annotated;; 5.6) echo "You choose the 5.6" break/break not commented;; Esacdone
Execute this script again: you will find that each time you choose, the execution will exit, and select is actually a loop, and the function of break is to exit the loop!
[[email protected] sbin]# sh 3.sh1) 5.12) 5.6#? 1YOU CHOOSE THE 5.1[[EMAIL PROTECTED] SBIN]# SH 3.SH1) 5.12 ) 5.6#? 2 /Choice is the one in front "#? "Symbol can be modified, can be modified with PS3, the following script you choose the 5.6
[Email protected] sbin]# vim 3.sh#!/bin/bashps3= "Please select a number:"/Add this line in the script and run again! Select Mysql_v in 5.1 5.6docase $mysql _v in5.1) echo ' You choose the 5.1 ' break;; 5.6) echo "You choose the 5.6" break;; Esacdone Run Result: [[email protected] sbin]# sh 3.sh1) 5.12 5.6Please Select a number:1you choose the 5.1
This article is from the "Custom" blog, so be sure to keep this source http://zidingyi.blog.51cto.com/10735263/1724899
Application of select in shell scripts