[H-GEN] Useful not so obvious tips

David Jericho davidj at tucanatech.com
Wed Oct 27 22:03:11 EDT 2004


Russell Stuart wrote:

>On Thu, 2004-10-28 at 11:10, Raymond Smith wrote:
>  
>
>>I'm curious, what is the advantage of less $(cmd) over 
>>less `cmd` ?
>>    
>>
>
>It nests.  For example, this works:
>
>  grep some-string $(grep -l other-string $(find . some-condition)))
>
>Also, I find typing mistakes are easier to find when
>using $(cmd).  I use it anytime I am not trying to
>write something portable - including on the command
>line.
>  
>

ksh and sh variants accept both `ls` and $(ls). csh on the other hand 
does not, only accepting `ls`.

To quote from the bash manpage:

When the old-style backquote form of substitution is used, backslash
retains its literal meaning except when followed by $, ‘, or \. The
first backquote not preceded by a backslash terminates the command sub-
stitution. When using the $(command) form, all characters between the
parentheses make up the command; none are treated specially.

Command substitutions may be nested. To nest when using the backquoted
form, escape the inner backquotes with backslashes.

And for you anti-cat advocates[1] out there, you can also do

for i in $(< input); ...

[1] You will die, for cat alone is best.[2]
[2] I felt like paraphrasing a Hong Kong kung fu movie quote. Points to 
the reader for knowing which one.

-- 
David Jericho
Senior Systems Administrator, Tucana Technologies





More information about the General mailing list