Warning messages for invalid options
by Faki from LinuxQuestions.org on (#5SWW5)
I have a bash function that allows the user to set options and parameters.
Code:heading [OPTIONS] PARAM...I have specified the following options
Code:-V, --version, -v, --verbosity, -u, --usage, -h, --help
--vlt, --blu, --grn, --ylw, --orn, --pur, --red, --wht, -mSTYI want to issue a warning for invalid options provided the invalid option is surrounded by available function options.
This is good
Code:heading --vlt -m1 PARAMSThis is also good, because -adv comes after all available options
Code:heading --vlt -m1 -adv DinBut this requires a warning, because --adv appears before available option -m1
Code:heading --vlt --adv -m1 DinThe function is listed here
Code:copt ()
{
while (( $# > 0 )); do
case $1 in
("-V"|"--version") shift ; return 0 ;;
("-v"|"--verbosity") vb=1 ; shift ;;
("-u"|"--usage") usg=1 ; shift ; return 0 ;;
("-h"|"--help") shift ; return 0 ;;
("--vlt") vlt=$(tput setaf 57) ; shift ;;
("--blu") blu=$(tput setaf 12) ; shift ;;
("--grn") grn=$(tput setaf 2) ; shift ;;
("--ylw") ylw=$(tput setaf 3) ; shift ;;
("--orn") orn=$(tput setaf 166) ; shift ;;
("--pur") pur=$(tput setaf 93) ; shift ;;
("--red") red=$(tput setaf 1) ; shift ;;
("--wht") wht=$(tput setaf 7) ; shift ;;
("-m"*) sty="${1#-m}" ; shift ;;
("--") shift ; break ;;
(*) break ;;
esac
done
}
Code:heading [OPTIONS] PARAM...I have specified the following options
Code:-V, --version, -v, --verbosity, -u, --usage, -h, --help
--vlt, --blu, --grn, --ylw, --orn, --pur, --red, --wht, -mSTYI want to issue a warning for invalid options provided the invalid option is surrounded by available function options.
This is good
Code:heading --vlt -m1 PARAMSThis is also good, because -adv comes after all available options
Code:heading --vlt -m1 -adv DinBut this requires a warning, because --adv appears before available option -m1
Code:heading --vlt --adv -m1 DinThe function is listed here
Code:copt ()
{
while (( $# > 0 )); do
case $1 in
("-V"|"--version") shift ; return 0 ;;
("-v"|"--verbosity") vb=1 ; shift ;;
("-u"|"--usage") usg=1 ; shift ; return 0 ;;
("-h"|"--help") shift ; return 0 ;;
("--vlt") vlt=$(tput setaf 57) ; shift ;;
("--blu") blu=$(tput setaf 12) ; shift ;;
("--grn") grn=$(tput setaf 2) ; shift ;;
("--ylw") ylw=$(tput setaf 3) ; shift ;;
("--orn") orn=$(tput setaf 166) ; shift ;;
("--pur") pur=$(tput setaf 93) ; shift ;;
("--red") red=$(tput setaf 1) ; shift ;;
("--wht") wht=$(tput setaf 7) ; shift ;;
("-m"*) sty="${1#-m}" ; shift ;;
("--") shift ; break ;;
(*) break ;;
esac
done
}