Cover V09, I07
Article
Listing 1
Listing 2
Listing 3

jul2000.tar


Listing 1: getopts.sh

# getopts demo
while getopts abz: name 
do
   case $name in
      a) aflag=1
         ;;
      b) bflag=1
         ;;
      z) zflag=$OPTARG
         ;;
      \?) echo "unknown option, terminating "
      exit 2
   esac
done
shift `expr $OPTIND - 1`
otherargs=${1}

if ! [ -z "$aflag" ]
then # echo if set
   echo "aflag set"
fi
if ! [ -z "$bflag" ]
then # echo if set
   echo "bflag set"
fi
if ! [ -z "$zflag" ]
then # echo if set
   echo "zflag is: "$zflag
fi
if ! [ -z "$otherargs" ]
then # echo if set
   echo "otherargs is: "$otherargs
fi