tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
* getopts fails
@ 1999-03-09 22:09 Edwin R Wolfe Jr.
  0 siblings, 0 replies; only message in thread
From: Edwin R Wolfe Jr. @ 1999-03-09 22:09 UTC (permalink / raw)
  To: tru64-unix-managers


I can't seem to get getopts to work in DU 4.0D, 4.0C, or 4.0.  I copied
the example from the man page into a file I named zzz:

            aflag=
            bflag=
            while getopts ab: name
            do
                   case $name in
                 a)  aflag=1;;
                 b)  bflag=1
                     bval="$OPTARG";;
                 ?)  printf "Usage: %s: [-a] [-b value] args\n" $0
                     exit 2;;
                 esac
            done
            if [ ! -z "$aflag" ]; then
                 printf "Option -a specified\n"
            fi
            if [ ! -z "$bflag" ]; then
                 printf 'Option -b "%s" specified\n' "$bval"
            fi
            shift $(($OPTIND - 1))
            printf "Remaining arguments are: %s\n" "$*"


xxx -a  begat the error: 
zzz: syntax error at line 21: `(' unexpected
which is the line with the shift command. commenting that out gave no
errors, but it failed to indicate the specified option.

I tried specifying #!/usr/bin/sh with the same result.  Specifying
the explicit path /usr/bin/getopts changed nothing. Using #!/usr/bin/csh 
gave the errors
aflag=: Command not found.
bflag=: Command not found.
while: Expression syntax.
 
Using #!ksh (not mentioned in the man page) made it work (even 
uncommenting the line with the shift command) - as long as I left it with
getopts instead of /usr/bin/getopts. (the explicit path gave no error, it 
just didn't report the argument).

Can someone familiar with scripts enlighten me as to just what's going on
here?  Surely there must be a way to use this in a sh script?

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1999-03-09 22:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1999-03-09 22:09 getopts fails Edwin R Wolfe Jr.

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox