From b16422a7f8b70676cef7a203f83f5d03ce66e89e Mon Sep 17 00:00:00 2001 From: Tomas Mudrunka Date: Fri, 5 Aug 2016 22:01:10 +0200 Subject: [PATCH] better getopts --- bash/getopts.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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 -- 2.30.2