shell case

阅读更多
case "$1" in
-a) echo "1";;
-b) echo "2";;
-c) echo "3";;
*) echo "error";;
esac

[root@localhost shell]# ./case.sh -a
1
[root@localhost shell]# ./case.sh -d
error


getopt
option=$1
while getopts a:b:c: option
do
	case "$option" in
	a) echo "1";;
	b) echo "2";;
	c) echo "3";;
	*) echo "error";;
	esac
done	

[root@localhost shell]# ./case.sh -a 1 -b 2 -c 3
1
2
3

你可能感兴趣的:(shell case)