Skip to content

Instantly share code, notes, and snippets.

@telnet2
Created August 12, 2019 22:24
Show Gist options
  • Save telnet2/a625903d4debd56237043a35b3ead122 to your computer and use it in GitHub Desktop.
Save telnet2/a625903d4debd56237043a35b3ead122 to your computer and use it in GitHub Desktop.
BASH getopts with mixed positional arguments
ARGS=()
while [ $# -gt 0 ]; do
unset OPTIND
unset OPTARG
while getopts v options; do
case $options in
v) VERBOSE=true ;;
esac
done
shift $((OPTIND - 1))
ARGS=("${ARGS[@]}" $1)
shift
done
CMD=${ARGS[0]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment