your usage string looks good
dgk's suggestion is an equivalent specification
but won;t change how getopts works

On Sun, 20 Sep 2009 17:40:58 -0700 Dan Rickhoff wrote:
> #! /bin/ksh
> USAGE="[+NAME?${0##*/}]
>        [+DESCRIPTION?Lookup a user.]
>        [u:username?The user's username.]:[user]
>        [s:surname?The user's last name.]:[last]"

> while getopts "$USAGE" opt
> do
>    case $opt in
>       u) un="$OPTARG" ;;
>       s) sn="$OPTARG" ;;
>      \?) print -u2 "The \"?\" case. OPTARG: \"$OPTARG\"."; exit -1 ;;
>       :) print -u2 "The \":\" case. OPTARG: \"$OPTARG\"."; exit -1 ;;
>    esac
> done

> shift OPTIND-1
> print "un: \"$un\", sn: \"$sn\", $...@} remaining args: $*"
> #-------------------------

> EXAMPLE executions that don't give what I expected:

> $ ./vas -u -s Doe "Hello world" x
> un: "-s", sn: "", 3 remaining args: Doe Hello world x

options that take arguments consume either
- the chars appended to the option operand
  e.g., -ufoo => un=foo
- the next operand if no chars are appended to the option operand
  e.g., -u foo => un=foo

even though the next operand above (-s) may look like an option
it is just the next operand to getops, so -s is the option value
for the -u option

currently the only mechanism for specifying the syntax of an option value
is # instead of : for numeric options
        [n:number?The number.]#[num]

> $ ./vas -u jdoe -s -- "Hello world" x
> un: "jdoe", sn: "--", 2 remaining args: Hello world x

> ALSO, if I add a colon character as the first character value of  
> getopt's "optstring" argument, then (for example) the following  
> doesn't give the expected usage message:

> $ ./vas --??
> The "?" case. OPTARG: "?".

the affect of a leading : is described in
        getopts --man

_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to