home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume7 / getopt.fix / text0000.txt < prev   
Encoding:
Text File  |  1986-11-30  |  673 b   |  33 lines

  1. Rich -
  2.  
  3.     Your /bin/sh example doesn't work on the Sun 3.0 /bin/sh,
  4. which is derived from SysV Rel2.  Besides the obvious error (getopt
  5. asking about flags "d:s" and then checking for -a and -b in the
  6. body), there are a few other problems.  Here's the corrected version
  7. for merging back into the man page (assuming it was globally wrong 
  8. and that this isn't due to our shell):
  9.  
  10. #!/bin/sh
  11. set -- `getopt "ab:" $@`
  12. if test $? != 0 ; then
  13.     echo "Read the documentation and try again."
  14.     exit 1
  15. fi
  16. Aflag=0
  17. Name=NONE
  18. for f
  19. do
  20.     case "$f" in
  21.         -a)    Aflag=1
  22.             ;;
  23.         -b)    shift
  24.             Name=$1
  25.             ;;
  26.         --)    break
  27.             ;;
  28.     esac
  29.     shift
  30. done
  31. echo Aflag=$Aflag / Name=$Name / Remaining args are $*
  32.  
  33.