ksh getopts неизвестная опция Ошибка

Я использую getopts для передачи опций в скрипт ksh, но опции не распознаются getopts.

Вот часть опций строки использования, которую я даю getopts

#OPTIONS
USAGE+="[w:week?print the whole week]"
USAGE+="[b:before?print the month up to and including the requested day]"
USAGE+="[a:after?print the month starting from the requested day to the end of the month or week]"
USAGE+="[d:day]#[day:=$(date "+%d"|sed 's/^0*//')?requested day]{[1-31]}"
USAGE+="[m:month]#[month:=$(date "+%m"|sed 's/^0*//')?month of requested day]{[1-12]}"
USAGE+="[y:year]#[year:=$(date "+%Y")?year of requested day.]"

А вот и мой блок getopts

while getopts "$USAGE" optchar
do
    echo $optchar
    case $optchar
    in
            w)      boolWEEK=true;
                    ;;

            b)      boolBEFORE=true;
                    ;;
            a)      boolAFTER=true;
                    ;;
            d)      day=$OPTARG
                    ;;
            m)      month=$OPTARG
                    ;;
            y)      year=$OPTARG
                    ;;
            esac
done

Вот результат запуска скрипта с опцией

$ ksh now.ksh -a
now.ksh: -a: unknown option
?
Usage: now.ksh [-wba] [-d day] [-m month] [-y year]
$

person Sam Ramirez    schedule 28.09.2013    source источник


Ответы (1)


Похоже, вы используете синтаксис ast getopts.

Я получил это, добавив [-] в начало строки USAGE:

USAGE+="[-][w:week?print the whole week]"

Возможно, [-] требуется для разрешения любой двусмысленности в строке параметров.

person Henk Langeveld    schedule 28.09.2013