2013-09-28 5 views
0

kopt 스크립트에 옵션을 전달하기 위해 getopts를 사용하고 있지만 getopts가 옵션을 인식하지 못합니다. 여기 ksh getopts 알 수없는 옵션 오류

내 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 

이 옵션을 사용하여 스크립트를 실행의 출력 차단 여기에 내가

#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가 할 줄 사용 문자열의 옵션 부분입니다 그리고

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

답변

0

ast getopts 구문을 사용하는 것으로 보입니다.

은 내가 USAGE 문자열의 앞에 [-]를 추가하여이 작업을 가지고 : 아마도 [-]는 옵션 문자열에서 모호성을 해결하기 위해 필요

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

합니다.