help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Setting variable with getopts


From: hancooper
Subject: Setting variable with getopts
Date: Mon, 09 Aug 2021 14:48:01 +0000

I am experiencing difficulties setting a variable `p` that is supposed to be 
set using getopts.

status ()
{

local vrb=1
local shortopts="Vuhp:"

while getopts $shortopts arg; do
case $arg in
# ........................................................
("V")
printf "%s\n" "V01 Jul 2021 Wk27"
return
;;
("u")
printf "%s\n" "-V, -u, -h"
printf "%s\n" "getopt-status --"
return
;;
("h")
printf "%s\n" "Description."
return
;;
("p")
p="$OPTARG"
printf '%s\n' "p, arg: $arg ; OPTARG: $OPTARG"
;;
(:)
echo "Current argument value, OPTARG: -$OPTARG" >&2
echo "Must supply an argument to -$OPTARG" >&2
;;
(?)
printf "%s" "Invalid option, OPTARG: $OPTARG"
;;
esac
done
shift "$OPTIND"

echo "p: $p"

}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]