!/bin/bash
while getopts "a:bc" arg #选项后面的冒号表示该选项需要参数
do
case OPTARG" #参数存在$OPTARG中
;;
b)
echo "b"
;;
c)
echo "c"
;;
?) #当有不认识的选项的时候arg为?
echo "unkonw argument"
exit 1
;;
!/bin/bash
while getopts "a:b:cdef" opt; do
case OPTARG"
;;
b)
echo "this is -b the arg is ! OPTARG"
;;
*)
echo "Invalid option: -$OPTARG"
;;
esac
done
网友评论