Created
April 18, 2013 02:43
-
-
Save sukima/5409618 to your computer and use it in GitHub Desktop.
An example of shell arguments without getopt or getopts
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/bash | |
while test $# -gt 0 | |
do | |
case $1 in | |
# Normal option processing | |
-h | --help) | |
# usage and help | |
;; | |
-v | --version) | |
# version info | |
;; | |
# ... | |
# Special cases | |
--) | |
break | |
;; | |
--*) | |
# error unknown (long) option $1 | |
;; | |
-?) | |
# error unknown (short) option $1 | |
;; | |
# FUN STUFF HERE: | |
# Split apart combined short options | |
-*) | |
split=$1 | |
shift | |
set -- $(echo "$split" | cut -c 2- | sed 's/./-& /g') "$@" | |
continue | |
;; | |
# Done with options | |
*) | |
break | |
;; | |
esac | |
# for testing purposes: | |
echo "$1" | |
shift | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment