csh question -- aliasing, quoting and the like
Maarten Litmaath
maart at cs.vu.nl
Wed Sep 20 13:41:03 AEST 1989
gjoost at westc.UUCP (Gertjan van Oosten) writes:
\...
\% alias killroy 'kill `ps ax | grep -w roy | grep -v grep | awk '{print $1}'`'
The `string' is broken into words as follows:
'kill `ps ax | grep -w roy | grep -v grep | awk '{print
$1}'`'
i.e. parts of the string aren't quoted.
Solution:
'kill ... awk '\''{print $1}'\''`'
^ ^ ^ ^ ^ ^
+-------------+ +----------+ +-+
\...
\% alias killroy 'rsh host kill `ps ax | grep -w roy | grep -v grep |
\ awk '{print $1}'`'
This would become:
alias killroy \
'rsh host kill '\''`ps ... awk '\'\\\'\''{print $1}'\'\\\'\''`'\'
Er, say that again?
Of course this isn't the optimal solution, regarding the number of quotes and
backslashes; it is, however, a GENERAL solution.
The following trick might be helpful:
set q = \'
set b = \\
set q1 = $b$q
set b1 = $b$b
set q2 = $b1$q1
# etc.
alias killroy \
'rsh host kill '$q'`ps ... awk '$q$q1$q'{print $1}'$q$q1$q'`'$q
^ ^ ^ ^ ^ ^
+---------------+ +-------------+ +----+
i.e. $q is a real quote, $q1 will be a real quote one interpretation level
deeper and so on.
--
creat(2) shouldn't have been create(2): |Maarten Litmaath @ VU Amsterdam:
it shouldn't have existed at all. |maart at cs.vu.nl, mcvax!botter!maart
More information about the Comp.unix.questions
mailing list