Publicando isso como memorando, o código a seguir funciona como pretendido:
#!/bin/ksh
#set -xv
USAGE=$'[-?\n@(#)$Id: '"script_name"
USAGE+=$'\n'"script_version"$' $\n]'
USAGE+="[m:mode?Sets notification mode.]:[mode:=ALL]"
USAGE+="{[S:SMS?SMS notification][M:MAIL?EMAIL notification][A:ALL?EMAIL and SMS notification]}"
while getopts "$USAGE" optchar;
do
case $optchar in
m) case "$OPTARG" in
M) echo -e "-m MAIL:\tOK!"
;;
S) echo -e "-m SMS:\tOK!"
;;
A) echo -e "-m SA:\tOK!"
;;
esac
;;
esac
done
Aqui está a saída:
$ ./usage.sh --man
SYNOPSIS
./usage.sh [ options ]
OPTIONS
-m, --mode=mode Sets notification mode.
SMS SMS notification
MAIL EMAIL notification
ALL EMAIL and SMS notification
The default value is ALL.
IMPLEMENTATION
version script_name script_version
$ ./usage.sh -m SMS
-m SMS: OK!
$ ./usage.sh -m pippo
./usage.sh: -m: pippo: unknown option argument value
Usage: ./usage.sh [-m mode]
Dessa forma, -m SMS
é equivalente a -m S
.