Skip to content

Instantly share code, notes, and snippets.

@ianldgs
Created October 29, 2018 13:27
Show Gist options
  • Select an option

  • Save ianldgs/9ba7dc302020a7f4b22de89e35ae9af9 to your computer and use it in GitHub Desktop.

Select an option

Save ianldgs/9ba7dc302020a7f4b22de89e35ae9af9 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Check this answer for more advanced stuff: https://stackoverflow.com/a/28466267/2502746
while getopts "*-:" arg; do
case $arg in
- ) LONG_OPTARG="${OPTARG#*=}"
case $OPTARG in
only-foo ) ONLY_FOO=1 ;;
only-bar ) ONLY_BAR=1 ;;
# "--" terminates argument processing
'' ) break ;;
* ) echo "Illegal option --$OPTARG" >&2; exit 2 ;;
esac ;;
# getopts already reported the illegal option
\? ) exit 2 ;;
esac
done
[ $ONLY_FOO ] && echo "only foo"
[ $ONLY_BAR ] && echo "only bar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment