Last active
August 29, 2015 14:06
-
-
Save chawkinsuf/7b9cc0e5e9339a252ba4 to your computer and use it in GitHub Desktop.
Process single character command line arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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