command substitution

William R. Pringle wrp at PRC.Unisys.COM
Thu Nov 8 16:21:27 AEST 1990


In article <5697 at alpha.cam.nist.gov> coleman at cam.nist.gov (Sean Sheridan Coleman X5672) writes:
>
>
>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. 
>Is there a way to "qoute" these so that those grave accent (`)
>will be passed down for another layer command substitution?

There seems to be a rash of articles about nested backquotes.  Since I
answered the last one, ...

You can use a backslash to quote backward quotes:

	`basename \`awk '{print $7}' /tmp/process.$$\``

However, since you are already paying the overhead of calling awk, then why
not do everything there?


	`awk '{print substr($7,1,index($7,".log")-1)}' /tmp/process.$$`

The index function returns the location of the string ".log" (you could also
use strlen($7)-4) and then the substr function prints the portion of the
string from the first character up to the character before the ".log"
(hence the index()-1)

Hope this helps.

Bill Pringle



More information about the Comp.unix.shell mailing list