Skip to content

Instantly share code, notes, and snippets.

@sukima
Created April 18, 2013 02:43
Show Gist options
  • Save sukima/5409618 to your computer and use it in GitHub Desktop.
Save sukima/5409618 to your computer and use it in GitHub Desktop.
An example of shell arguments without getopt or getopts
#!/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