Skip to content

Instantly share code, notes, and snippets.

@chawkinsuf
Last active August 29, 2015 14:06
Show Gist options
  • Save chawkinsuf/7b9cc0e5e9339a252ba4 to your computer and use it in GitHub Desktop.
Save chawkinsuf/7b9cc0e5e9339a252ba4 to your computer and use it in GitHub Desktop.
Process single character command line arguments
USAGE=`printf "Usage: %s [-a] text\n -a : Do A" $(basename $0)`
# Get the options
aflag=
while getopts 'a' OPTION; do
case $OPTION in
a) aflag=1
;;
?) echo "$USAGE"
exit 1
;;
esac
done
shift $(($OPTIND - 1))
# 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