Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!littlei!ogcvax!schaefer From: schaefer@ogcvax.UUCP (Barton E. Schaefer) Newsgroups: comp.unix.questions Subject: Re: mulltiword arguments in C-shell Message-ID: <1476@ogcvax.UUCP> Date: Wed, 28-Oct-87 14:00:41 EST Article-I.D.: ogcvax.1476 Posted: Wed Oct 28 14:00:41 1987 Date-Received: Wed, 4-Nov-87 03:19:10 EST References: Reply-To: schaefer@ogcvax.UUCP (Barton E. Schaefer) Distribution: na Organization: Oregon Graduate Center, Beaverton, OR Lines: 72 In article strong@tc.fluke.COM (Norm Strong) writes: >I have a problem: > My question, Mr. Anthony, is: How can I get the shell to handle these >multi-word arguments all the way through to the output and dump them out with >the quotes still around them, so that the next program will also recognize them >as a single argument? > >Norm (strong@fluke) This is an EASY one! The csh supports a number of "colon modifiers" that can be applied to variables and history substitutions to either cause or prevent substitutions. The one you want is ":q" (for "quote"), which (among other things) prevents separation of a variable into words when it is referenced. To see how this works, try the following (remember that $#var is replaced by the number of words in var): % set one="This is one string" % echo $#one 1 % set four=($one) % echo $#four 4 % set onetoo=($one:q) % echo $#onetoo 1 % In a csh script, colon modifiers can be appended to any of the "positional" variables ($1, $2, $3, etc) EXCEPT $0 (the script file name). You must also remember to use :q whenever you reference any variable that is an aggregate of quoted variables. For example, # Separate option flags and other arguments set opts=() others=() while ($#argv) switch ($1) case -* : # note :q on ref to $opts set opts=($opts:q $1:q) breaksw default : # similarly for $others set others=($others:q $1:q) endsw shift end A quick summary of colon modifiers (from 4.3 BSD csh manual) Modifier Result Usable in substitution ------- ------ ---------------------- h Take head of path History or variable t Take tail of path History or variable r Take root of name History or variable e Take extension (.xxx) of name History or variable[*] s/p/r/ Substitute r for p History only & Repeat previous substitution History only gX Apply modifier X globally Where X is usable p Print but don't execute History only q Quote History or variable x Like q but make words History or variable [*] The csh manual omits this for variables, but it works on my system Only ONE colon modifier can currently be used on any substitution. -- Bart Schaefer CSNET: schaefer@cse.ogc.edu UUCP: ...{tektronix,verdix}!ogcvax!schaefer "It could have been worse. I could have woken up and been Robert Bork." -- Joe Garagiola, after his broadcast partner angered Twins fans