Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uwm.edu!linac!att!ucbvax!cel.cummins.com!philip From: philip@cel.cummins.com (Philip D. Pokorny) Newsgroups: comp.sys.apollo Subject: Re: AEGIS Shell argument processing... Message-ID: <9106131931.AA08669@cel.cummins.com> Date: 13 Jun 91 19:31:14 GMT Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 50 Doug Vander Wilt writes: > After many years programming with the AEGIS shell (/com/sh) I wonder if > I'm missing out on some easier argument processing methods. Is there a > "shift" style command to shift arguments left? I haven't had any success > referring to them with a variable index, e.g.: ^0 ^1 .. ^^n > > I currently use the following form to process an unknown number of shell > arguments, but it won't properly handle quoted arguments: > (e.g.: $ argtest a 'b c' d ) I remember having to do something like this when proccessing the equivalent of a shell array... Here's what I came up with: #!/com/sh # Print shell arguments. eon n := 0 while(( ^"set -c args @^^n" <> "" )) do arg := ^"set -c args @^^n" args (( "Argument " + ^n + ": " + ^arg )) n := ^n + 1 enddo This uses indirection via the 'set -c' shell command to evaluate the argument @^^n once (to ^3, etc) and then again. (to get the third argument, etc) The down-side to this scheme is that you may have to be carefull about null strings as arguments. (You could check all 127 arguments or if you are expecting an argument that might be null it's not a problem.) A sample run: $ test.sh 1 2 3 '^1' '4 5' Argument 0: test.sh Argument 1: 1 Argument 2: 2 Argument 3: 3 Argument 4: ^1 Argument 5: 4 5 $ Sincerely, Philip D. Pokorny philip@cel.cummins.com :)