home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / unix / volume07 / getopt.fix < prev    next >
Encoding:
Internet Message Format  |  1988-09-11  |  1.1 KB

  1. From mlandau@Diamond.BBN.COM Fri Aug 29 15:21:54 1986
  2. Received: by mirror.TMC.COM (4.12/UUCP-Project/rel-1.0/08-20-86)
  3.     id AA09715; Fri, 29 Aug 86 15:21:48 edt
  4. Received: by Diamond.BBN.COM; Fri, 29 Aug 86 14:20:15 EDT
  5. Date: Fri, 29 Aug 86 14:20:15 EDT
  6. From: Matt Landau <mlandau@Diamond.BBN.COM>
  7. Message-Id: <8608291820.AA02073@Diamond.BBN.COM>
  8. To: mirror!rs
  9. Subject: Getopt(1) from mod.sources
  10. Status: R
  11.  
  12. Rich -
  13.  
  14.     Your /bin/sh example doesn't work on the Sun 3.0 /bin/sh,
  15. which is derived from SysV Rel2.  Besides the obvious error (getopt
  16. asking about flags "d:s" and then checking for -a and -b in the
  17. body), there are a few other problems.  Here's the corrected version
  18. for merging back into the man page (assuming it was globally wrong 
  19. and that this isn't due to our shell):
  20.  
  21. #!/bin/sh
  22. set -- `getopt "ab:" $@`
  23. if test $? != 0 ; then
  24.     echo "Read the documentation and try again."
  25.     exit 1
  26. fi
  27. Aflag=0
  28. Name=NONE
  29. for f
  30. do
  31.     case "$f" in
  32.         -a)    Aflag=1
  33.             ;;
  34.         -b)    shift
  35.             Name=$1
  36.             ;;
  37.         --)    break
  38.             ;;
  39.     esac
  40.     shift
  41. done
  42. echo Aflag=$Aflag / Name=$Name / Remaining args are $*
  43.  
  44.