X-Git-Url: http://git.harvie.cz/?a=blobdiff_plain;f=bash%2Fgetopts.sh;h=f65d50ba73ec76dd298d1cafef8f84e31f364092;hb=3278bd05b32d60782f649a074e8c43943c9c31c2;hp=270410ae89dac1d7f1c07c8c70d0c6e709572b60;hpb=21c4e16782bf8fee46cf478cd933a9ba11cca1c7;p=mirrors%2FPrograms.git diff --git a/bash/getopts.sh b/bash/getopts.sh index 270410a..f65d50b 100755 --- a/bash/getopts.sh +++ b/bash/getopts.sh @@ -1,7 +1,18 @@ #!/bin/sh -while getopts "a:b:c:d:" OPT; do +while getopts ":a:b:c:d:f" OPT; do echo "$OPT ==> $OPTARG"; + case $OPT in + a ) ahoj=$OPTARG;; + + '?') echo "Unknown option: -$OPTARG" >&2; exit 1;; + ':') echo "Missing option argument for -$OPTARG" >&2; exit 2;; + * ) echo "Unimplemented option: -$OPT" >&2; exit 3;; + esac done +echo shift $(($OPTIND -1)); echo "Rest: $@"; + +: ${ahoj:=default} +echo ahoj: $ahoj