linux getopts用法

今天看学习了getopets总结下结果:

作用:用这个东东可以打命令一样 <命令  -选项 参数>

#!/bin/bash

while getopts xyz: args 2> /dev/null
do
        case $args in
        x)      echo " you entered -x";;
        y)      echo " you entered -y";;
        z)      echo " you entered -z";
                echo " \$OPTARG is $OPTARG ";;
        \?)     echo "Usage opts4 [-xy] [-z arguments]";
                exit 1;;
        esac
done
echo "\OPTIND is 1.
        \OPTIND is $OPTIND.
        `expr $OPTIND - 1`. ";

  

  

posted @ 2012-06-29 20:50  tywei  阅读(303)  评论(0编辑  收藏  举报