From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96079038515577.tru64-unix-managers.marc@archive.invalid> From: "Edwin R Wolfe Jr." Date: Tue, 09 Mar 1999 22:09:50 +0000 To: tru64-unix-managers Subject: getopts fails X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96079038515577 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?