.sh & getopts

Aiza aiza21 at comclark.com
Sat Jun 5 12:51:34 UTC 2010


Robert Bonomi wrote:
> m
>> From owner-freebsd-questions at freebsd.org  Thu Jun  3 23:36:28 2010
>> Date: Fri, 04 Jun 2010 12:35:56 +0800
>> From: Aiza <aiza21 at comclark.com>
>> To: "questions at freebsd.org" <questions at freebsd.org>
>> Cc: 
>> Subject: .sh & getopts
>>
>> Have this code
>>
>> shift; while getopts :ugr: arg; do case ${arg} in
>>     u) action="freebsd-update";;
>>     g) action="freebsd-upgrade";;
>>     r) action="freebsd-rollback";;
>>     ?) exerr ${cmd_usage};;
>> esac; done; shift $(( ${OPTION} -1 ))
>>
>>
>> Command being executed looks like this, cmd action -flags aaaa bbbb
>>
>> Only a single -flag in allowed on the command.
>>
>> $# gives a count of parms ie: aaaa bbbb. in this example a count of 2.
>>
>> I am looking for something to check that holds the number of flags on 
>> the command. so I can code. if flag_count gt 1 = error
>>
>> Is there such a thing created by getopts?
> 
> Why bother??
> 
>  flag_count=0
>  shift; while getopts :ugr: arg
>    if flag_count = 1; then
>      exerr ${cmd_usage}
>    fi 
>    flag_count=1;
>    do case ${arg} in
>    {{blah-blah}}
> 

nope dont work.

If the flags are counted at all it has to be a function of getopts



More information about the freebsd-questions mailing list