Monday 2 January 2012

Linux bash getopts sample

 

bash getopts example

# adding : at beginning for more user friendly option error handling 
while getopts ":a:b:c" Option
# Initial declaration.
#
do
case $Option in
# w ) CMD=$OPTARG; FILENAME="PIMSLogList.txt"; TARGET="logfiles"; ;;
  a) a=$OPTARG ;;
d ) b=$OPTARG ;;
c ) c=FlogForCInOn ;;
* ) echo "Usage $basename -a A -b B -c arguments"
esac
done
shift $(($OPTIND - 1))
# now deal with the arguments

No comments:

Post a Comment