bash getopts example
while getopts ":c:sd" Option
# Initial declaration.
# c, s, and d are the flags expected.
# The : after flag 'c' shows it will have an option passed with it.
do
case $Option in
# w ) CMD=$OPTARG; FILENAME="PIMSLogList.txt"; TARGET="logfiles"; ;;
s ) PORT=20 ;;
d ) DEBUG=true ;;
c ) CMD=$OPTARG ;;
* ) echo "Not recognized argument"; exit -1 ;;
esac
done
shift $(($OPTIND - 1))
# Initial declaration.
# c, s, and d are the flags expected.
# The : after flag 'c' shows it will have an option passed with it.
do
case $Option in
# w ) CMD=$OPTARG; FILENAME="PIMSLogList.txt"; TARGET="logfiles"; ;;
s ) PORT=20 ;;
d ) DEBUG=true ;;
c ) CMD=$OPTARG ;;
* ) echo "Not recognized argument"; exit -1 ;;
esac
done
shift $(($OPTIND - 1))
Comments