home *** CD-ROM | disk | FTP | other *** search
Paul Falstad's zsh script | 1992-05-19 | 2.0 KB | 66 lines |
- #!/bin/zsh
- #
- # test.zsh - Z shell script to test out the parseargs command!
- #
-
- NAME="`basename $0`"
-
- 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 -- number 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, args, 'args -- any remaining arguments',
- ENDOFARGS
- "
- export ARGUMENTS
-
- ## set defaults ##
- typeset count='1' ## only do once unless otherwise specified
- typeset dirname='.' ## default to current directory
- typeset xflag='' ## default xflag is false
- typeset yflag='TRUE' ## default yflag is true
- typeset sepch=',' ## default separator is a comma
- typeset groups
- typeset files
-
- ## parse command-line ##
- parseargs -s zsh -e ARGUMENTS -u -- "$NAME" $argv[@] >/tmp/tmp$$
- if [ $status -ne 0 ] ; then
- rm -f /tmp/tmp$$
- exit 2 ## improper syntax (or just wanted usage)
- fi
-
- ## evaluate results from parseargs and remove temporary file ##
- INTERPRET="."
- $INTERPRET /tmp/tmp$$
- rm -f /tmp/tmp$$
-
- ## print arguments ##
- echo "ARGUMENTS:"
- echo "=========="
- echo "Groups='${groups[@]}'"
- echo "Count='$count'"
- echo "Directory='$dirname'"
- echo "XFlag='$xflag'"
- echo "YFlag='$yflag'"
- echo "SepChar='$sepch'"
- echo "Name='$name'"
- echo "Files='${files[@]}'"
- if [ -z "$string_flag" ] ; then
- string="default string"
- else
- string=${string:-'\!string arg ommitted on cmd-line\!'}
- fi
- echo "String='$string'"
- echo "New Positional Parameters='$args[@]'"
-
- ## echo usage ##
- parseargs -a "$ARGUMENTS" -U "$NAME"
-