方法一:
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 ls11 ;;12 3)13 who14 ;;15 4)16 pwd17 ;;18 *)19 echo -e "\n"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 ls11 ;;12 who)13 who14 ;;15 pwd)16 pwd17 ;;18 *)19 echo "Please inpurt number 1-4"20 ;;21 esac22 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 ls10 ;;11 3)12 who13 ;;14 4)15 pwd16 ;;17 *)18 echo -e "\n"19 echo "Please input number 1-4!!!"20 ;;21 esac