[ale] Stupid Bash Question
Lightner, Jeff
JLightner at water.com
Thu Mar 8 07:58:38 EST 2012
Nested back ticks don’t really work. At more than one presentation a couple of years back I saw different script “experts” explain why using $() was better but don’t recall all their reasoning. I can say that once I started using it I wondered why I had stuck to back ticks for so long. It does allow nesting and also makes it easier to read code as you’re not likely to confuse a paren with a single quote, double quote, back tick or worse yet a line that has all 3.
________________________________
From: ale-bounces at ale.org [mailto:ale-bounces at ale.org] On Behalf Of Mike Fletcher
Sent: Thursday, March 08, 2012 7:19 AM
To: Atlanta Linux Enthusiasts
Subject: Re: [ale] Stupid Bash Question
On Mar 7, 2012, at 10:57 PM, Jim Kinney <jim.kinney at gmail.com<mailto:jim.kinney at gmail.com>> wrote:
I don't recall the source but I read the backticks are to concidered deprecated. Maybe in the bash 4 release notes?
The $() form is the POSIX shell standard now IMSMR. All the kornish shells have supported it for a while now so it wouldn't surprise me to see it get deprecated
Also to nitpick on the original code:
* echoing the backticked output of hostname is kind of roundabout. Just run it
* the separate grep before awk could be replaced with just a single awk
awk '$0 !~ /swap/ {print $3}'
Or (for the whitespaceophobes :)
perl -lane '!/swap/&&print$F[2]'
On Mar 7, 2012 5:12 PM, "Michael Campbell" <michael.campbell at gmail.com<mailto:michael.campbell at gmail.com>> wrote:
One advantage of $() over `` is that you get matching opposing pairs of parens and nested commands are a bit easier to parse.
echo $(foo bar $(baz blah) and then bleh)
as opposed to
echo `foo bar `baz blah` and then bleh`
For me another win is that I generally run shells inside emacs buffers so I can make use of the paren-matching feature from within emacs to help out.
On Wed, Mar 7, 2012 at 11:25 AM, Benjie <benjie.godfrey at gmail.com<mailto:benjie.godfrey at gmail.com>> wrote:
It looks like you missed placing a single quote after the 'echo `hostname` command. That would prevent awk from interpreting its print command.
On Wed, Mar 7, 2012 at 11:07 AM, Brandon Colbert <colbert.brandon at gmail.com<mailto:colbert.brandon at gmail.com>> wrote:
I am trying figure out what the heck is wrong with awk here.
for i in $(seq 1 1); do ssh 127.0.0.$i 'echo `hostname`; if [ `free -m | grep -i swap | awk '{print $3}'` > 1000 ]; then sudo echo reclaim; else echo hey; fi'; done
The command works, but I get an error about awk: Any suggestions?
deblapatl01
awk: cmd. line:1: {print
awk: cmd. line:1: ^ unexpected newline or end of string
hey
_______________________________________________
Ale mailing list
Ale at ale.org<mailto:Ale at ale.org>
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
--
"The most important thing to remember about drunks is that drunks are far more intelligent than non-drunks. They spend a lot of time talking in pubs, unlike workaholics who concentrate on their careers and ambitions, who never develop their higher spiritual values, who never explore the insides of their head like a drunk does." -- Shane McGowan
_______________________________________________
Ale mailing list
Ale at ale.org<mailto:Ale at ale.org>
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
_______________________________________________
Ale mailing list
Ale at ale.org<mailto:Ale at ale.org>
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
_______________________________________________
Ale mailing list
Ale at ale.org<mailto:Ale at ale.org>
http://mail.ale.org/mailman/listinfo/ale
See JOBS, ANNOUNCE and SCHOOLS lists at
http://mail.ale.org/mailman/listinfo
Athena®, Created for the Cause™
Making a Difference in the Fight Against Breast Cancer
How can I show my support for bottled water?
Take a minute to sign a petition in support of bottled water. Your signature COUNTS! Available through the <http://> www.bottledwatermatters.org/luv-bottledwater-iframe/dswaters<http://www.bottledwatermatters.org/luv-bottledwater-iframe/dswaters> website, the goal is 50,000 signatures. Please include your personal email address when submitting. Once completed, share the website with your family and friends, to ensure as many bottled water supporters as possible sign the petition
---------------------------------
CONFIDENTIALITY NOTICE: This e-mail may contain privileged or confidential information and is for the sole use of the intended recipient(s). If you are not the intended recipient, any disclosure, copying, distribution, or use of the contents of this information is prohibited and may be unlawful. If you have received this electronic transmission in error, please reply immediately to the sender that you have received the message in error, and delete it. Thank you.
----------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.ale.org/pipermail/ale/attachments/20120308/8b3a41fc/attachment-0001.html
More information about the Ale
mailing list