shell getopt

 

 

#!/bin/sh

 

usage()

{

 cat<<EOF

 Usage: test [-a test1]  [-b test2]  [-h]

      -a: test1

      -b: test2

      -h: print help

EOF

}

[ $# -eq 0 ] && usage && exit 0;

 

aa=""

bb=""

 

while getopts "a:b:h"  opt

do

    case $opt in

          a)  aa=$OPTARG;;

          b)  bb=$OPTARG;;

          h)  usage; exit 0;;

    esac

done

 

 

[ -z $aa ] && usage && exit 0;

[ -z $bb ] && usage && exit 0;

echo $aa;

echo $bb;

 

你可能感兴趣的:(shell,getopt)