Skip to content

Instantly share code, notes, and snippets.

@chawkinsuf
Last active August 29, 2015 14:06
Show Gist options
  • Save chawkinsuf/7d98b70837fb232585cc to your computer and use it in GitHub Desktop.
Save chawkinsuf/7d98b70837fb232585cc to your computer and use it in GitHub Desktop.
Process full command line arguments
USAGE=`printf "Usage: %s [--doa] [--textoption text] text\n -a, --doa : Do A\n --textoption : Store text" $(basename $0)`
# Get inputs
aflag=""
textoption=""
while test $# -gt 0; do
case $1 in
# Normal options
--textoption)
textoption="$2"
shift
;;
-a|--doa)
aflag=1
;;
# Help
--help)
echo "$USAGE"
exit
;;
# Unknown options
--*|-?)
echo "$USAGE"
exit 1
;;
# Done with options
*)
break
;;
esac
shift
done
# Check for additional options
if [ -z "$1" -o ${#*} -ne 1 ]; then
echo "$USAGE"
exit 1
fi
# Store the text option
text="$1"
# Do A
if [ -z "$aflag" ]; then
echo "Do A"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment