home *** CD-ROM | disk | FTP | other *** search
- #!/bin/sh
- # test.sh - Bourne shell script to test out the parseargs command!
- #
- NAME="`basename $0`"; DOT=".";
-
- ARGUMENTS="
- '?', ARGHIDDEN, argUsage, NULL, 'Help : print usage and exit',
- 'S', ARGVALOPT, argStr, string, 'STRing : optional string arg',
- 'g', ARGLIST, argStr, groups, 'newsGROUPS : groups to test',
- 'r', ARGOPT, argInt, count, 'REPcount <# to repeat each group>',
- 'd', ARGOPT, argStr, dirname, 'DIRectory : working directory',
- 'x', ARGOPT, argBool, xflag, 'Xflag : turn on X-mode',
- 'y', ARGOPT, argUBool, yflag, 'Yflag : turn off Y-mode',
- 's', ARGOPT, argChar, sepch, 'SEPchar : field separator',
- 'f', ARGLIST, argStr, files, 'files : files to process',
- 'n', ARGREQ|ARGPOS, argStr, name, 'name : name to use',
- ' ', ARGLIST, argStr, -- , 'argv : any remaining arguments',
- ENDOFARGS
- "
- export ARGUMENTS
-
- yflag='TRUE' ## set defaults (dir="."; count=1; sepch=',') ##
-
- ## parse command-line and save assignments in a temporary file ##
- parseargs -s sh -e ARGUMENTS -u -- "$NAME" "$@" > /tmp/tmp$$
- if [ $? -ne 0 ]
- then rm -f /tmp/tmp$$; exit 2 ## non-zero status (usage given)
- fi
-
- ## evaluate results from parseargs and remove temporary file
- $DOT /tmp/tmp$$; rm -f /tmp/tmp$$
-
- ## echo the parsed arguments (use defaults if not defined)
- echo "ARGUMENTS:"
- echo "=========="
- echo "Name='$name', Count='${count:-1}'"
- echo "XFlag='$xflag', YFlag='$yflag'"
- echo "Directory='${dirname:-"."}', SepChar='${sepch:-","}'"
- echo "Groups='$groups'"
- echo "Files='$files'"
- if [ "$string_flag" ]
- then string=${string:-"!string arg ommitted on cmd-line!"}
- else string="default string"
- fi
- echo "String='$string'"
- echo "New Positional Parameters='$*'"
-
- parseargs -a "$ARGUMENTS" -U "$NAME" ## print usage ##
-