Last active
October 17, 2021 09:57
-
-
Save nikvdp/5e23113c842dd220865cacb8cbaa0871 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
rest=() | |
while [[ $# -ge 1 ]]; do | |
arg="$1" | |
shift | |
case "$arg" in | |
-f|--foo) | |
foo=true | |
;; | |
-p|--param-that-takes-an-arg) | |
params_arg="$1" | |
shift # extra shift so we don't re-parse the param's arg | |
;; | |
*) | |
# optionally keep unknown options around to be handled later | |
rest=("${rest[@]}" "$arg") | |
;; | |
esac | |
done | |
set -- "${rest[@]}" "$1" # let anything we didn't parse out above be | |
echo "foo: $foo" | |
echo "arg for -p: $params_arg" | |
echo "Unparsed args: $@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment