1.case語句控制流
#!/bin/sh
echo "please input number 1 to 3"
read number
case $number in
1) echo "you input 1"
;;
2|3) echo "you input 2 or 3"
;;
*) echo "error! the number you input isn't 1 to 3"
;;
esac
按順序執行,若匹配不到前面的1,2,3,到匹配到*則輸出相應信息
2. select語句控制
select var in ... ; do
break
done
$var
#!/bin/sh echo "What is your favourite firuit?" echo "1) Apple" echo "2) Orange" echo "3) Banana" read number case $number in 1)echo "your favourite firuit is Apple." ;; 2)echo "your favourite firuit is Orange." ;; 3)echo "your favourite firuit is Banana." ;; esac
#!/bin/sh echo "What is your favourite firuit?" select var in "Apple" "Orange" "Banana";do break done echo "your favourite firuit is $var."
執行以上腳本,均可實現下面交互式功能
What is your favourite firuit?
1) Apple
2) Orange
3) Banana
#? 1
your favourite firuit is Apple.