Created
October 29, 2018 13:27
-
-
Save ianldgs/9ba7dc302020a7f4b22de89e35ae9af9 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
| #!/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