方法一:
1 #!/bin/bash 2 3 echo "*cmd meau** 1--date 2--ls 3--who 4--pwd" 4 read -p "Please input number:" number 5 case $number in 6 1) 7 date 8 ;; 9 2) 10 ls 11 ;; 12 3) 13 who 14 ;; 15 4) 16 pwd 17 ;; 18 *) 19 echo -e " " 20 echo "Please input number 1-4!!!" 21 ;; 22 esac
方法二:
1 #!/bin/bash 2 echo "Pleae chose a number" 3 select number in date ls who pwd 4 do 5 case $number in 6 date) 7 date 8 ;; 9 ls) 10 ls 11 ;; 12 who) 13 who 14 ;; 15 pwd) 16 pwd 17 ;; 18 *) 19 echo "Please inpurt number 1-4" 20 ;; 21 esac 22 done
day2 解析:
1、使用case语法就可以实现啦,不用想的太复杂
day2=参考答案=~ps.不是唯一答案哦
1 #!/bin/bash 2 echo "*cmd meau** 1--date 2--ls 3--who 4--pwd" 3 read -p "Please input number:" number 4 case $number in 5 1) 6 date 7 ;; 8 2) 9 ls 10 ;; 11 3) 12 who 13 ;; 14 4) 15 pwd 16 ;; 17 *) 18 echo -e " " 19 echo "Please input number 1-4!!!" 20 ;; 21 esac