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

猜你喜欢

转载自xiangjie88.iteye.com/blog/2391398
今日推荐