home *** CD-ROM | disk | FTP | other *** search
Plan 9 rc shell script | 1992-05-19 | 1.8 KB | 52 lines |
- #!/bin/rc
- # test.rc - rc shell script to test out the parseargs command!
- #
- # NOTE: This script tests Byron Rakitzis' version of rc. NOT the
- # Plan 9 version (there are a few differences such as the use
- # of "else" instead of "if not" and the use of "$^variable").
- #
- 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 <# 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, "argv : any remaining arguments",
- ENDOFARGS
- '
-
- yflag='TRUE' ## set defaults (dir="."; count=1; sepch=',') ##
- count=1
- sepch=','
-
- ## parse command-line and save assignments in a temporary file ##
- if ( parseargs -s rc -e ARGUMENTS -u -- $^NAME $* >/tmp/tmp$pid ) {
- ## evaluate results from parseargs and remove temporary file
- . /tmp/tmp$pid; rm -f /tmp/tmp$pid
- } else {
- rm -f /tmp/tmp$pid;
- exit 2 ## non-zero status (usage given)
- }
-
-
- ## echo the parsed arguments (use defaults if not defined)
- echo 'ARGUMENTS:'
- echo '=========='
- echo 'Name='"$name", 'Count='$count
- echo 'XFlag='"$xflag", 'YFlag='"$yflag"
- echo 'Directory='"$dirname", 'SepChar='"$sepch"
- echo 'Groups='"$groups"
- echo 'Files='"$files"
- echo 'string_flag='$^string_flag
- echo 'String='"$string"
- echo 'argv=' "$argv"
-
- parseargs -a $^ARGUMENTS -U $^NAME ## print usage ##
-