shell脚本中case语句中变量值如何读取,我写了一个脚本。但是运行后,报错。

2024-12-18 13:48:09
推荐回答(2个)
回答1:

read CHOICE
case $CHOICE in
1) mountusb;;
2) umountusb;;
3) display;;
4) cpdisktousb;;
5) cpusbtodisk;;
0) quit;;
*) echo "Invalid Choice! Correct Choice is (0--5)"
sleep 4 clear;;

回答2:

[root@XP-24-35 test]# cat a.sh
#!/bin/bash
read -p "please input a number: " number
case $number in
1 ) echo "hello"
;;
2 ) echo "hehe"
;;
3 ) echo "ok"
;;
* ) echo "error"
;;
esac
[root@XP-24-35 test]# sh a.sh
please input a number: 1
hello
[root@XP-24-35 test]# sh a.sh
please input a number: asd
error