当输入1时,会运行date, 输入2时运行ls, 依此类推。
参考脚本:
{{{密码回复可见}}}
echo "cmd mean** 1---date 2--ls 3--who 4--pwd "
read -p "Please input one num:" -t 3 x
echo
case $x in
1)
date
;;
2)
ls
;;
3)
who
;;
4)
pwd
;;
*)
while :
do
echo "please input num 1-4"
read -p "Please input one num:" -t 3 x
echo
done
;;
esac
read -p " please input number : " a
case $a in
1)
/bin/date
;;
2)
/bin/ls
;;
3)
/usr/bin/who
;;
4)
/bin/pwd
;;
*)
echo " the number you set is not aliable "
esac
read -p '*cmd meau** 1---date 2--ls 3--who 4--pwd 5--quit'
echo
select n in date ls who pwd quit
do
case $n in
date)
date
;;
ls)
ls
;;
who)
who
;;
pwd)
pwd
;;
quit)
exit
;;
*)
echo "please input a number(1-4)"
;;
esac
done
#! /bin/bash
echo '*cmd menu*'
echo -e '1--date\n2--ls\n''3--who\n4--pwd'
cmd_menu() {
select i in 1 2 3 4
do
case $i in
1) date
break
;;
2) ls
break
;;
3) who
break
;;
4)
echo `pwd`
break
;;
*)
echo 'only 1-4'
exit 1
;;
esac
done
}
cmd_menu
read -p "pls input a number(1-4):" n
case $n in
1)
date
;;
2)
ls
;;
3)
who
;;
4)
pwd
;;
*)
echo "Pls enter a right number"
;;
esac
- <p>#!/bin/bash</p><p>#显示命令如下*cmd meau** 1---date 2--ls 3--who 4--pwd
- read -p "Please enter a number: " n
- if [ $n -eq 1 ]
- then
- echo `date`
- elif [ $n -eq 2 ]
- then
- echo `ls`
- elif [ $n -eq 3 ]
- then
- echo `who`
- elif [ $n -eq 4 ]
- then
- echo `pwd`
- else
- echo "It's not a number in [1-4]"
- fi</p>
echo "*cmd meau** 1---date 2--ls 3--who 4--pwd"
read -p "Please input a number: " n
case $n in
1)
date
;;
2)
ls
;;
3)
who
;;
4)
pwd
;;
*)
echo "Please input a number in 1-4"
esac
echo "*cmd meau** 1--date 2--ls 3--who 4--pwd"
read -p "please enter the number 1-4:" i
case $i in
1)
date
;;
2)
ls
;;
3)
who
;;
4)
pwd
;;
esac
read -p "Please input a number: " n
case $n in
1)
date;;
2)
ls;;
3)
who;;
4)
pwd;;
*)
echo "You must input a number from 1 to 4!";;
esac
read -p "please input a number:" x
case $x in
1)
date +%F
echo "*cmd meau** 1---date"
;;
2)
ls
echo "*cmd meau** 2--ls"
;;
3)
who
echo "*cmd meau** 3--who"
;;
4)
pwd
echo "*cmd meau** 4--pwd"
;;
esac
不知道是不是这种理解
- echo **cmd menu**:
- echo 1---date
- echo 2--ls
- echo 3--who
- echo 4--pwd
- read -p "Input a number:" n
- case $n in
- 1)
- echo `date`
- ;;
- 2)
- echo `ls`
- ;;
- 3)
- echo `who`
- ;;
- 4)
- echo `pwd`
- ;;
- esac
- #!/bin/bash
- select a in 1 2 3 4
- do
- case "$a" in
- 1)echo `date`
- break
- ;;
- 2)echo `ls`
- break
- ;;
- 3)echo `who`
- break
- ;;
- 4)echo `pwd`
- ;;
- esac
- done
#
#
while true
do
echo "
*cmd meau**
1---date
2--ls
3--who
4--pwd
q--exit"
read -p "please enter a number:" a
case $a in
1)
date
;;
2)
ls
;;
3)
who
;;
4)
pwd
;;
Q|q)
exit 0
;;
*)
echo "your enter is wrong !!"
esac
done
##written by 20160909
if [ "$1" == "" ];then
echo "Please choose the number you want to do ;"
read -p "1、date;2、ls;3、who;4、pwd:" n
echo "$n"
case $n in
1)
date
;;
2)
ls
;;
3)
who
;;
4)
pwd
;;
esac
fi
#!/bin/bash
echo "*cmd meau** 1---date 2--ls 3--who 4--pwd"
while :; do
read -p "Please input a number to choose the function above: " n
if (( $n != 1 )) && (( $n != 2 )) && (( $n != 3 )) && (( $n != 4 )) ; then
echo "Your input is wrong .Please input the correct selection"
else
case $n in
1)
date
exit
;;
2)
ls
exit
;;
3)
who
exit
;;
4)
pwd
exit
;;
esac
fi
done
echo "*cmd meau** 1---date 2--ls 3--who 4--pwd"
read -p "please enter a number: " n
case $n in
1)
date
;;
2)
ls
;;
3)
who
;;
4)
pwd
;;
*)
echo "please input one of the 1 2 3 4"
esac
#Description: This script is to test case feature.
#Author: Jiazhi Yang
#Date: 16/11/2016
#Script Name: caseexample2.sh
read -p "please enter any digit from 1 to 4: " i
case $i in
1) date
;;
2) ls
;;
3) who
;;
4) pwd
;;
*) echo "Error,you have to enter any digit between here: {1|2|3|4}"
sleep 1
echo " 1: execuate 'date' command."
echo " 2: execuate 'ls' command."
echo " 3: execuate 'who' command."
echo " 4: execuate 'pwd' command."
;;
esac
#!/bin/bash
read -p "input a number:" n
case $n in
1)
date
;;
2)
ls
;;
3)
who
;;
4)
pwd
;;
*)
echo "cmd meau**"
;;
esac
while :;doread -p "*cmd meau** 1---date 2--ls 3--who 4--pwd 5--exit " nif [ -z $n ] then echo "Please input a number."fin1=`echo $n|sed 's/[1-5]//g'`if [ ! -z $n1 ] then echo "Please input a number between 1 to 4."fi case $n in 1) echo `date` ;; 2) echo `ls` ;; 3) echo `who` ;; 4) echo `pwd` ;; 5) echo "bye~" exit 1 ;; esacdone
read -p "*cmd meau** 1--date 2--ls 3--who 4--pwd: " a
5 case $a in
6 1)
7 date
8 ;;
9 2)
10 ls
11 ;;
12 3)
13 who
14 ;;
15 4)
16 pwd
17 ;;
18 *)
19 echo "Error"
20 ;;
21 esac
#! /bin/bash
read -p "Please select comman 1---date 2--ls 3--who 4--pwd: " n
case $n in
1)
date
;;
2)
ls
;;
3)
who
;;
4)
pwd
;;
*)
echo "try agine"
esac
用 select 也可以进行操作
#! /bin/bash
echo "please chose a number"
echo
select command in date ls who pwd
do
case $command in
pwd)
pwd
;;
who)
who
;;
ls)
ls
;;
date)
date
;;
*)
echo "retry please"
;;
esac
done
编辑回复