select单独使用
cat select01.sh #!/bin/bash echo "Which car do you prefer?" select CAR in Benz Audi VolksWagen do break done echo "You chose $CAR"
运行结果
sh select01.sh Which car do you prefer? 1) Benz 2) Audi 3) VolksWagen #? 1 You chose Benz
select和case结合使用
cat select02.sh #!/bin/bash select DAY in Mon Tue Wed Thu Fri Sat Sun do case $DAY in Mon) echo "Today is Monday";; Tue) echo "Today is Tuesday";; Wed) echo "Today is Wednesday";; Thu) echo "Today is Thursday";; Fri) echo "Today is Friday";; Sat|Sun) echo "You can have a rest today";; *) echo "Unknown input ,exit now" && break;; esac done
select结合case使用
sh select02.sh 1) Mon 2) Tue 3) Wed 4) Thu 5) Fri 6) Sat 7) Sun #? 1 Today is Monday #? 6 You can have a rest today #? 8 Unknown input ,exit now
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。