Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!uakari.primate.wisc.edu!aplcen!haven!umbc3!umbc5.umbc.edu!rostamia From: rostamia@umbc5.umbc.edu (Rouben Rostamian) Newsgroups: comp.unix.questions Subject: Re: csh question -- aliasing, quoting and the like Keywords: csh alias quotes Message-ID: <2315@umbc3.UMBC.EDU> Date: 20 Sep 89 04:23:27 GMT References: <498@westc.UUCP> Sender: newspost@umbc3.UMBC.EDU Reply-To: rostamia@umbc5.umbc.edu.UUCP (Rouben Rostamian) Organization: University of Maryland, Baltimore County Lines: 47 In article <498@westc.UUCP> gjoost@westc.UUCP (Gertjan van Oosten) writes: >The basic problem is as follows: I want an alias to kill all processes >called 'roy'. > >% alias killroy 'kill `ps ax | grep -w roy | grep -v grep | awk '{print $1}'`' > >The problem comes down to having single quotes within single quotes. The >single quotes around the 'awk' argument can't be double quotes, because they >would lead to the evaluation of '$1'. Escaping the '$' is no use within >double quotes. ...The rest of the article omitted. General idea first: Suppose A, B, C, are fragments of shell expressions, and suppose that you wish to enclose the expression - A 'B' C - in a pair of single quotes. [Note: I use hyphens to delineate the expressions; they are NOT parts of the the expressions.] The obvious solution - 'A 'B' C' - will not do, because in effect it creates the quoted strings - 'A ' - and - ' C' -, and squeezes an unquoted - B - in between. This is important, so make sure you see this before reading on! Now that you see this, the rest is easy: What you want is - 'A '\''B'\'' C' - which is parsed as 'A ' + \' + 'B' + \' + ' C'. Get it? Now back to your problem. Applying the general idea above, you can see that the statement: alias killroy \ 'kill '\`'ps ax | grep -w roy | grep -v grep | awk ' \''{print $1}'\'\` does the trick. In fact, the pair of quotes surrounding "kill" are not necessary and may be dropped. An alternative solution, somewhat uglier, is to drop all unnecessary single quotes and to "escape" all special characters in sight: alias killroy \ kill \` ps ax \| grep -w roy \| grep -v grep \| awk \'\{print \$1\}\'\` I hope that this helps. Rouben Rostamian Phone: 301 455-2458 Department of Mathematics e-mail: University of Maryland Baltimore Counnty Rostamian@umbc.bitnet Baltimore, MD 21228 rostamia@umbc3.umbc.edu