Last active
July 6, 2020 10:08
-
-
Save r10r/8faeac4a7ac04e99490512b0a05e0386 to your computer and use it in GitHub Desktop.
Bash command wrapper with partial option parsing.
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 | |
cmd=mycmd | |
# parse a subset of all options | |
while true; do | |
while getopts c:u:b: arg 2>/dev/null; do | |
case $arg in | |
"a") | |
arga=$OPTARG | |
;; | |
"b") | |
argb=$OPTARG | |
;; | |
"c") | |
argc=$OPTARG | |
;; | |
esac | |
done | |
# advance to the next option when getopts fails to parse the current option | |
((OPTIND++)) | |
[ $OPTIND -gt $# ] && break | |
done | |
exec $cmd $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment