Gentoo Archives: gentoo-user

From: Alex Schuster <wonko@×××××××××.org>
To: gentoo-user@l.g.o
Subject: Re: [gentoo-user] Re: FIXED 3D
Date: Fri, 09 Oct 2009 16:13:14
Message-Id: 200910091813.02158.wonko@wonkology.org
In Reply to: Re: [gentoo-user] Re: FIXED 3D by Alan McKinnon
1 Alan McKinnon writes:
2
3 > On Thursday 08 October 2009 20:33:01 Neil Bothwick wrote:
4 > > On Thu, 08 Oct 2009 18:54:26 +0300, Nikos Chantziaras wrote:
5 > > > And it's usually quicker to type with backticks instead of $():
6 > >
7 > > But nowhere near as clear.
8 >
9 > And it's quicker to type "$(" - muscle memory - than to do the whole
10 > hunt- peek-peck thing to find the ` key - I can't touch type it, have
11 > to *look* for it
12
13 Uh...
14
15 > :-)
16
17 ... okay :) I for myself was happy when I learnt that $() exists, and
18 prefer it over the backticks notation. Although it's more to type. But it
19 looks better, and I want my scripts to look good.
20
21
22 > > Note you can also nest commands when using $(), which you can't do
23 > > with backticks.
24 >
25 > That's neat. But,
26 >
27 > please provide an example where an actual sane human would actually use
28 > it. Coz I can't think of one...
29
30 Hey, I'm doing this all the time in my scripts. First example I found is
31 this, but there are many more:
32
33 total=$( mydf -2 "$dir" )
34 format=$( printf "%%%dd" $( echo $total | wc -c ) )
35 log 0 " Total: %s MB\n" "$( printf "$format" "$total" )"
36 log 0 " Used: %s MB\n" "$( printf "$format" "$( mydf -3 "$dir" )" )"
37 log 0 " Free: %s MB\n" "$( printf "$format" "$( mydf -4 "$dir" )" )"
38
39 That was before I knew about ${#total}, so in fact no nesting would be
40 required in line 2.
41
42 I think I also had tree levels of nesting somewhere, but that was too much
43 fpr Nedit's syntax highlighting, so I de-nested this a little.
44
45 Wonko the Sane