1.getopts命令

#!/bin/bash
while getopts "a:bc" arg #选项后面的冒号表示该选项需要参数
do
        case $arg in
             a)
                echo "a's arg:$OPTARG" #参数存在$OPTARG中
                ;;
             b)
                echo "b"
                ;;
             c)
                echo "c"
                ;;
             ?)  #当有不认识的选项的时候arg为?
            echo "unkonw argument"
        exit 1
        ;;
        esac
done
[root@zhu ~]# sh a.sh -a nan -b
a's arg:nan
b
[root@zhu ~]# sh zhu.sh -n mingyuexin -l -m -g
the name is mingyuexin
l
m
zhu.sh: illegal option -- g
unknown arg
[root@zhu ~]# cat zhu.sh
#!/bin/bash
while getopts "lmn:" s
do
    case $s in
        l)
            echo "l"
            ;;
        m)
            echo "m"
            ;;
        n)
            echo "the name is $OPTARG"
           ;;
        ?)
            echo "unknown arg"
    esac
done


getopts optstring name [args]
#getopts 不支持长选项
# optstring :为字符串 如"ab:c" 若是字符后跟冒号,表示该字符选项后需跟参数 ,参数和选项用空格分开。
#当shell执行行,选项后的参数保存在OPTARG变量中
#当有不是指定的选项时name值返回?