Skip to content

Instantly share code, notes, and snippets.

@r10r
Last active July 6, 2020 10:08
Show Gist options
  • Save r10r/8faeac4a7ac04e99490512b0a05e0386 to your computer and use it in GitHub Desktop.
Save r10r/8faeac4a7ac04e99490512b0a05e0386 to your computer and use it in GitHub Desktop.
Bash command wrapper with partial option parsing.
#!/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