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

  1. #!/bin/ksh
  2. #
  3. #    test.ksh - Korn 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,    -- ,    'argv -- 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 ksh -e ARGUMENTS -uip -- "$NAME" "$@" >/tmp/tmp$$
  35. if [ $? -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. print "ARGUMENTS:"
  47. print "=========="
  48. print "Groups='${groups[@]}'"
  49. print "Count='$count'"
  50. print "Directory='$dirname'"
  51. print "XFlag='$xflag'"
  52. print "YFlag='$yflag'"
  53. print "SepChar='$sepch'"
  54. print "Name='$name'"
  55. print "Files='${files[@]}'"
  56. if [ "$string_flag" ] ; then
  57.   string=${string:-"!string arg ommitted on cmd-line!"}
  58. else
  59.   string="default string"
  60. fi
  61. print "String='$string'"
  62. print "New Positional Parameters='$*'"
  63.  
  64. ## print usage ##
  65. parseargs -a "$ARGUMENTS" -U "$NAME"
  66.