command substitution
Chris Torek
chris at mimsy.umd.edu
Thu Nov 8 17:50:14 AEST 1990
In article <5697 at alpha.cam.nist.gov> coleman at cam.nist.gov
(Sean Sheridan Coleman X5672) writes:
>I want to write the following independent statements into one line:
>
>set tmp= `awk '{print $7}' /tmp/process.$$`
>set date = `basename $tmp`
Since your syntax above is C shell (and incorrect C shell at that---the
first line sets the variable tmp to nothing, and sets the variable whose
name is produced by the awk command to nothing), the answer is `there is
no way to do it'.
In sh, it is easy:
date=`basename \`awk '{print $7}' /tmp/process.$$\``
>I really want to do the following:
>
>set date = `basename `awk '{print $7}' /tmp/process.$$``
>
>Unfortuantly, the second set of Grave accent marks for command
>substitution for the basename command will confuse the shell.
Well no; actually, their main function is to confuse *you*. :-) They
simply close the others. This is:
run "basename"
run ""
splice output from basename and "" onto both ends of the awk
set date to the result.
>Is there a way to "qoute" these so that those grave accent (`)
>will be passed down for another layer command substitution?
No; the C shell internals make this impossible. (There are several
places that assume that backquote expansion happens only to a depth
of one.) If you somehow manage to trick the `scanner' all you will
get is a broken shell.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain: chris at cs.umd.edu Path: uunet!mimsy!chris
More information about the Comp.unix.shell
mailing list