处理选项_查找选项_处理含值的选项
#!/bin/bash
# 命令行选项要求额外的参数时,脚本必须能够检测到并正确地加以处理。
# extract command-line options and values
echo
while [ -n "$1" ]
do
case "$1" in
-a) echo "found the -a option";;
-b) param=$2
echo "found the -b option with parameter value $param"
shift;;
-c) echo "found the -c option";;
--) shift
break;;
*) echo "$1 is not an option";;
esac
shift
done
echo
count=1
for param in $@
do
echo "parameter #$count: $param"
count=$[ $count + 1 ]
done
exit
# ./extractoptionsvalues.sh -a -b Bvalue -d