[SFS] bash - things you can't do with backticks

Jed Walker jedwa@comcast.net
Mon, 24 Mar 2014 09:51:29 -0600


This is a multipart message in MIME format.

------=_NextPart_000_0053_01CF4746.A1C0BE80
Content-Type: text/plain;
	charset="utf-8"
Content-Transfer-Encoding: quoted-printable

Indeed! The backticks just annoy me, I too prefer $() if definitely =
reads better. And makes more sense. I=E2=80=99m sure I=E2=80=99ve nested =
it in a script somewhere, if I remember and can find it I=E2=80=99ll let =
you know.

=20

From: sfs-admin@thegeek.nu [mailto:sfs-admin@thegeek.nu] On Behalf Of =
David L. Willson
Sent: Monday, March 24, 2014 9:24 AM
To: sfs
Cc: Jeffrey S. Haemer
Subject: [SFS] bash - things you can't do with backticks

=20

I always use something like this "$( expression )" to get "the output of =
expression", rather than backticks like this "` expression `" and teach =
others to do likewise for two reasons: It's more readable and it's =
nestable. But, when teaching, I can never come up with a good example of =
nesting, so today, I happen to have one. I want to delete all the files =
in this directory, except the newest three.


rm $( ls -tr | head -n $(( $( ls -tr | wc -l ) - 3 )))


It has some big bugs and I cannot lie, but it does demonstrate nesting.

--
David L. Willson
Teacher, Engineer, Evangelist
RHCE+Satellite CCAH Network+ A+ Linux+ LPIC-1 UbuntuCP NovellCLA
Mobile 720-333-LANS(5267)
http://sofree.us

This is a good time for a r3VOLution.




------=_NextPart_000_0053_01CF4746.A1C0BE80
Content-Type: text/html;
	charset="utf-8"
Content-Transfer-Encoding: quoted-printable

<html xmlns:v=3D"urn:schemas-microsoft-com:vml" =
xmlns:o=3D"urn:schemas-microsoft-com:office:office" =
xmlns:w=3D"urn:schemas-microsoft-com:office:word" =
xmlns:m=3D"http://schemas.microsoft.com/office/2004/12/omml" =
xmlns=3D"http://www.w3.org/TR/REC-html40"><head><meta =
http-equiv=3DContent-Type content=3D"text/html; charset=3Dutf-8"><meta =
name=3DGenerator content=3D"Microsoft Word 14 (filtered =
medium)"><style><!--
/* Font Definitions */
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Tahoma;
	panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
p
	{mso-style-priority:99;
	margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
span.EmailStyle18
	{mso-style-type:personal-reply;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:8.5in 11.0in;
	margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext=3D"edit" spidmax=3D"1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext=3D"edit">
<o:idmap v:ext=3D"edit" data=3D"1" />
</o:shapelayout></xml><![endif]--></head><body lang=3DEN-US link=3Dblue =
vlink=3Dpurple><div class=3DWordSection1><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'>Indeed! The backticks just annoy me, I too prefer $() if definitely =
reads better. And makes more sense. I=E2=80=99m sure I=E2=80=99ve nested =
it in a script somewhere, if I remember and can find it I=E2=80=99ll let =
you know.<o:p></o:p></span></p><p class=3DMsoNormal><span =
style=3D'font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497=
D'><o:p>&nbsp;</o:p></span></p><div><div =
style=3D'border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in =
0in 0in'><p class=3DMsoNormal><b><span =
style=3D'font-size:10.0pt;font-family:"Tahoma","sans-serif"'>From:</span>=
</b><span style=3D'font-size:10.0pt;font-family:"Tahoma","sans-serif"'> =
sfs-admin@thegeek.nu [mailto:sfs-admin@thegeek.nu] <b>On Behalf Of =
</b>David L. Willson<br><b>Sent:</b> Monday, March 24, 2014 9:24 =
AM<br><b>To:</b> sfs<br><b>Cc:</b> Jeffrey S. Haemer<br><b>Subject:</b> =
[SFS] bash - things you can't do with =
backticks<o:p></o:p></span></p></div></div><p =
class=3DMsoNormal><o:p>&nbsp;</o:p></p><div><p class=3DMsoNormal><span =
style=3D'color:black'>I always use something like this &quot;$( =
expression )&quot; to get &quot;the output of expression&quot;, rather =
than backticks like this &quot;` expression `&quot; and teach others to =
do likewise for two reasons: It's more readable and it's nestable. But, =
when teaching, I can never come up with a good example of nesting, so =
today, I happen to have one. I want to delete all the files in this =
directory, except the newest three.<br><br><br>rm $( ls -tr | head -n =
$(( $( ls -tr | wc -l ) - 3 )))<br><br><br>It has some big bugs and I =
cannot lie, but it does demonstrate nesting.<br><br>--<br>David L. =
Willson<br>Teacher, Engineer, Evangelist<br>RHCE+Satellite CCAH Network+ =
A+ Linux+ LPIC-1 UbuntuCP NovellCLA<br>Mobile 720-333-LANS(5267)<br><a =
href=3D"http://sofree.us">http://sofree.us</a><br><br>This is a good =
time for a =
r3VOLution.<br><br><o:p></o:p></span></p></div></div></body></html>
------=_NextPart_000_0053_01CF4746.A1C0BE80--