diff --git a/teil27/family.sh b/teil27/family.sh new file mode 100755 index 0000000..e2dafdd --- /dev/null +++ b/teil27/family.sh @@ -0,0 +1,71 @@ +#! /usr/bin/bash + +usage() { +local name=${0##*/} + + cat <<-EOF + Usage: ${name} [-h || --help] -f || --father -m || --mother -s || --son -d || --daughter -b || --baby + + checks if all members of the Simpsons's family are present: exits 0 + exists 1 otherwise + EOF +} +FATHER="" +MOTHER="" +SON="" +DAUGHTER="" +BABY="" + +VALID_ARGS=$(getopt -o hf:m:s:d:b: --long help,father:,mother:,sun:,daughter:,baby: -- "$@") +if [[ $? -ne 0 ]]; then + exit 1; +fi + +echo "VALID_ARGS=${VALID_ARGS}" +eval set -- "$VALID_ARGS" + +while [ : ]; do + echo "current parameter: ${1},value=${2}" + case "$1" in + -h | --help) + usage + exit 0 + shift # simple parameter shift by one + ;; + -f | --father) + FATHER=${2} + shift 2 # parameter with argument sift two times + ;; + -m | --mother) + MOTHER=${2} + shift 2 + ;; + -s | --son) + SON=${2} + shift 2 + ;; + -d | --daughter) + DAUGHTER=${2} + shift 2 + ;; + -b | --baby) + BABY=${2} + shift 2 + ;; + --) # end of loop + shift + break + ;; + *) + echo "unrecognized parameter ${1}" + exit 1 + ;; + esac + +done + +echo "FATHER=${FATHER}" +echo "MOTHER=${MOTHER}" +echo "SON=${SON}" +echo "DAUGHTER=${DAUGHTER}" +echo "BABY=${BABY}"