home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume29 / parseargs / part01 / test.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1992-05-19  |  1.7 KB  |  49 lines

  1. #!/bin/sh
  2. #    test.sh - Bourne shell script to test out the parseargs command!
  3. #
  4. NAME="`basename $0`";  DOT=".";
  5.  
  6. ARGUMENTS="
  7.   '?', ARGHIDDEN, argUsage, NULL,    'Help : print usage and exit',
  8.   'S', ARGVALOPT, argStr,   string,  'STRing : optional string arg',
  9.   'g', ARGLIST,   argStr,   groups,  'newsGROUPS : groups to test',
  10.   'r', ARGOPT,    argInt,   count,   'REPcount <# to repeat each group>',
  11.   'd', ARGOPT,    argStr,   dirname, 'DIRectory : working directory',
  12.   'x', ARGOPT,    argBool,  xflag,   'Xflag : turn on X-mode',
  13.   'y', ARGOPT,    argUBool, yflag,   'Yflag : turn off Y-mode',
  14.   's', ARGOPT,    argChar,  sepch,   'SEPchar : field separator',
  15.   'f', ARGLIST,   argStr,   files,   'files : files to process',
  16.   'n', ARGREQ|ARGPOS, argStr, name,  'name : name to use',
  17.   ' ', ARGLIST,   argStr,   -- ,     'argv : any remaining arguments',
  18.   ENDOFARGS
  19. "
  20. export ARGUMENTS
  21.  
  22. yflag='TRUE'     ## set defaults (dir="."; count=1; sepch=',') ##
  23.  
  24. ## parse command-line and save assignments in a temporary file ##
  25. parseargs -s sh -e ARGUMENTS -u -- "$NAME" "$@" > /tmp/tmp$$
  26. if [ $? -ne 0 ]
  27.   then rm -f /tmp/tmp$$; exit 2  ## non-zero status (usage given)
  28. fi
  29.  
  30. ## evaluate results from parseargs and remove temporary file
  31. $DOT /tmp/tmp$$;  rm -f /tmp/tmp$$
  32.  
  33. ## echo  the parsed arguments (use defaults if not defined)
  34. echo "ARGUMENTS:"
  35. echo "=========="
  36. echo "Name='$name', Count='${count:-1}'"
  37. echo "XFlag='$xflag', YFlag='$yflag'"
  38. echo "Directory='${dirname:-"."}', SepChar='${sepch:-","}'"
  39. echo "Groups='$groups'"
  40. echo "Files='$files'"
  41. if [ "$string_flag" ]
  42.   then string=${string:-"!string arg ommitted on cmd-line!"}
  43.   else string="default string"
  44. fi
  45. echo "String='$string'"
  46. echo "New Positional Parameters='$*'"
  47.  
  48. parseargs -a "$ARGUMENTS" -U "$NAME"     ## print usage ##
  49.