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
时间: 2024-10-18 13:03:14