Compare commits

...

2 Commits

Author SHA1 Message Date
Olli Graf 81a7c96f7f teil22 2 weeks ago
Olli Graf 89557b8e36 Revert "„teil23/parseargs.sh“ ändern" 2 months ago
  1. 0
      teil22/ebene0/0.txt
  2. 23
      teil23/parseargs.sh
  3. 15
      teil24/family.sh

0
teil22/ebene0/0.txt

23
teil23/parseargs.sh

@ -8,13 +8,14 @@ display_help() {
echo " -f, --file <file> Specify a file"
echo " -n, --number <num> Specify a number (default: 42)"
}
# Universelle Parameterparser-Funktion
parse_args() {
POSITIONAL=()
while [[ $# -gt 0 ]]; do
case "${1}" in
case "$1" in
-h|--help)
display_help
display_help "$@"
exit 0
;;
-v|--verbose)
@ -22,7 +23,7 @@ parse_args() {
shift
;;
-f|--file)
if [[ -z "${2}" || "${2}" == -* ]]; then
if [[ -z "$2" || "$2" == -* ]]; then
echo "Error: --file requires a non-empty argument."
exit 1
fi
@ -30,11 +31,11 @@ parse_args() {
shift 2
;;
-n|--number)
if [[ -z "${2}" || "${2}" == -* ]]; then
if [[ -z "$2" || "$2" == -* ]]; then
echo "Error: --number requires a non-empty argument."
exit 1
fi
NUMBER="${2}"
NUMBER="$2"
shift 2
;;
--) # Explicit end of options
@ -56,4 +57,14 @@ parse_args() {
# Defaults
VERBOSE="${VERBOSE:-false}"
NUMBER="${NUMBER:-42}"
}
}
# Aufruf der Funktion mit allen Skriptargumenten
parse_args "$@"
# Beispielnutzung
echo "Verbose mode: $VERBOSE"
echo "File: ${FILE:-<not set>}"
echo "Number: $NUMBER"
echo "Positional arguments: $@"

15
teil24/family.sh

@ -0,0 +1,15 @@
#! /usr/bin/bash
case ${1} in
'Homer'|'Marge'|'Bart'|'Lisa')
echo "Familie Simpson"
;;
'Ned'|'Maude'|'Todd'|'Rod')
echo "Familie Flanders"
;;
'Clancy'|'Sarah'|'Ralph')
echo "Familie Wiggum"
;;
esac
Loading…
Cancel
Save