Alan McKinnon writes:

> On Thursday 08 October 2009 20:33:01 Neil Bothwick wrote:
> > On Thu, 08 Oct 2009 18:54:26 +0300, Nikos Chantziaras wrote:
> > > And it's usually quicker to type with backticks instead of $():
> >
> > But nowhere near as clear.
>
> And it's quicker to type "$(" - muscle memory - than to do the whole
> hunt- peek-peck thing to find the ` key - I can't touch type it, have
> to *look* for it

Uh...

> :-)

... okay :) I for myself was happy when I learnt that $() exists, and 
prefer it over the backticks notation. Although it's more to type. But it 
looks better, and I want my scripts to look good.


> > Note you can also nest commands when using $(), which you can't do
> > with backticks.
>
> That's neat. But,
>
> please provide an example where an actual sane human would actually use
> it. Coz I can't think of one...

Hey, I'm doing this all the time in my scripts. First example I found is 
this, but there are many more:

total=$( mydf -2 "$dir" )
format=$( printf "%%%dd" $( echo $total | wc -c ) )
log 0 "  Total:    %s MB\n" "$( printf "$format" "$total" )"
log 0 "  Used:     %s MB\n" "$( printf "$format" "$( mydf -3 "$dir" )" )"
log 0 "  Free:     %s MB\n" "$( printf "$format" "$( mydf -4 "$dir" )" )"

That was before I knew about ${#total}, so in fact no nesting would be 
required in line 2.

I think I also had tree levels of nesting somewhere, but that was too much 
fpr Nedit's syntax highlighting, so I de-nested this a little.

        Wonko the Sane

Reply via email to