erste Version von family.sh

This commit is contained in:
2026-02-06 06:52:33 +01:00
parent 06f622b37f
commit ea5900d9ab

71
teil27/family.sh Executable file
View File

@@ -0,0 +1,71 @@
#! /usr/bin/bash
usage() {
local name=${0##*/}
cat <<-EOF
Usage: ${name} [-h || --help] -f || --father <name> -m || --mother <name> -s || --son <name> -d || --daughter <name> -b || --baby <name>
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}"