Last active
August 29, 2015 14:16
-
-
Save dstokes/d0204bd933c3f44c3e9c to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# | |
# Parse command flags and positional arguments regardless | |
# of argument order | |
# | |
# placeholder for postional arguments | |
PARAMS="" | |
# iterate through all command-line arguments | |
while (( "$#" )); do | |
case "$1" in | |
# | |
# Custom flag processing | |
# | |
# -r|--role) | |
# # do stuff | |
# shift 2 # flag with value | |
# ;; | |
# | |
# Standard processing | |
# | |
--) # end option parsing | |
shift | |
break | |
;; | |
-*|--*=) # unsupported flags | |
echo "Error: Unsupported flag $1" | |
exit 1 | |
;; | |
*) # save postitional args | |
PARAMS="$PARAMS $1" | |
shift | |
;; | |
esac | |
done | |
# reimport position arguments as $1 $2 etc | |
eval set -- "$PARAMS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment