home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume29 / parseargs / part02 / test.zsh < prev    next >
Encoding:
Paul Falstad's zsh script  |  1992-05-19  |  2.0 KB  |  66 lines

  1. #!/bin/zsh
  2. #
  3. #    test.zsh - Z shell script to test out the parseargs command!
  4. #
  5.  
  6. NAME="`basename $0`"
  7.  
  8. ARGUMENTS="
  9.   '?', ARGHIDDEN, argUsage, NULL,    'Help -- print usage and exit',
  10.   'S', ARGVALOPT, argStr,   string,  'STRing -- optional string arg',
  11.   'g', ARGLIST,   argStr,   groups,  'newsGROUPS -- groups to test',
  12.   'r', ARGOPT,    argInt,   count,   'REPcount -- number to repeat each group',
  13.   'd', ARGOPT,    argStr,   dirname, 'DIRectory -- working directory',
  14.   'x', ARGOPT,    argBool,  xflag,   'Xflag -- turn on X-mode',
  15.   'y', ARGOPT,    argUBool, yflag,   'Yflag -- turn off Y-mode',
  16.   's', ARGOPT,    argChar,  sepch,   'SEPchar -- field separator',
  17.   'f', ARGLIST,   argStr,   files,   'files -- files to process',
  18.   'n', ARGREQ|ARGPOS, argStr, name,  'name -- name to use',
  19.   ' ', ARGLIST,   argStr,   args,    'args -- any remaining arguments',
  20.   ENDOFARGS
  21. "
  22. export ARGUMENTS
  23.  
  24. ## set defaults ##
  25. typeset count='1'          ## only do once unless otherwise specified
  26. typeset dirname='.'        ## default to current directory
  27. typeset xflag=''           ## default xflag is false
  28. typeset yflag='TRUE'       ## default yflag is true
  29. typeset sepch=','          ## default separator is a comma
  30. typeset groups
  31. typeset files  
  32.  
  33. ## parse command-line ##
  34. parseargs -s zsh -e ARGUMENTS -u -- "$NAME" $argv[@] >/tmp/tmp$$
  35. if [ $status -ne 0 ] ; then
  36.   rm -f /tmp/tmp$$
  37.   exit 2  ## improper syntax (or just wanted usage)
  38. fi
  39.  
  40. ## evaluate results from parseargs and remove temporary file ##
  41. INTERPRET="."
  42. $INTERPRET /tmp/tmp$$
  43. rm -f /tmp/tmp$$
  44.  
  45. ## print arguments ##
  46. echo "ARGUMENTS:"
  47. echo "=========="
  48. echo "Groups='${groups[@]}'"
  49. echo "Count='$count'"
  50. echo "Directory='$dirname'"
  51. echo "XFlag='$xflag'"
  52. echo "YFlag='$yflag'"
  53. echo "SepChar='$sepch'"
  54. echo "Name='$name'"
  55. echo "Files='${files[@]}'"
  56. if [ -z "$string_flag" ] ; then
  57.   string="default string"
  58. else
  59.   string=${string:-'\!string arg ommitted on cmd-line\!'}
  60. fi
  61. echo "String='$string'"
  62. echo "New Positional Parameters='$args[@]'"
  63.  
  64. ## echo usage ##
  65. parseargs -a "$ARGUMENTS" -U "$NAME"
  66.