Article 5T71P Handling default values when using getopts t::

Handling default values when using getopts t::

by
Faki
from LinuxQuestions.org on (#5T71P)
I have written the following function and want to set a default if user does not supply a value to the option "-t". Haw can I handle this?

Code:myfunc ()
{
local nt ng
local OPTIND OPTARG
local shortopts=":t::g:"
while getopts "$shortopts" arg; do
case $arg in
("t") nt=${OPTARG} ;;
("g") ng=${OPTARG} ;;
(*)
printf "getopts: Error Reporting Mode | Silent "
printf "arg: $arg"
case $arg in
(":")
printf " No value provided to -${OPTARG} option."
printf " Give a value, e.g. \"-${OPTARG} 3\"."
break
;;
("?")
printf "User option not dufined in shortopts."
printf "Invalid -${OPTARG} option provided."
break
;;
esac
fi
break
;;
esac
done
printf '%s\n' "nt: $nt | ng: $ng"
}latest?d=yIl2AUoC8zA latest?i=hv2wxOzMW5I:2Dm0_itndgA:F7zBnMy latest?i=hv2wxOzMW5I:2Dm0_itndgA:V_sGLiP latest?d=qj6IDK7rITs latest?i=hv2wxOzMW5I:2Dm0_itndgA:gIN9vFw
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments