LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-30-2009, 01:53 PM   #1
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
Question [bash] gawk curiosity: `backticks` work fine , but switching to $(this) doesn't


Code:
root@reactor:/etc/rc.d/lutelwall# service=$(echo $aservice | gawk '{ gsub("\\\(.*\\\)","") ; print }' )
gawk: warning: escape sequence `\(' treated as plain `('
gawk: warning: escape sequence `\)' treated as plain `)'

root@reactor:/etc/rc.d/lutelwall# service=`echo $aservice | gawk '{ gsub("\\\(.*\\\)","") ; print }' `
root@reactor:/etc/rc.d/lutelwall#
So, it isn't a big deal, I'm just curious if anyone has a good idea why the above gawk function gives the warning when $() are around it, but when using backticks, it's fine. In theory, I should be able to use $() right?

This line is from a much larger script, which I went through the other day and replaced literally dozens of gawk+backtick usage with $() to modernize it, and every other instance seems fine; just this single line acts up.

I can leave the backticks, but would like to know what it is about this particular line that's so special..

Sasha
 
Old 11-30-2009, 01:59 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
$ needs to be in double-quotes.

Single quotes (AKA "hard quotes") protects everything from being expanded by the shell.
 
Old 11-30-2009, 02:07 PM   #3
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Original Poster
Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
I tried it with double quotes, like:

blah="$( foo foo foo )"

and it still did the same. Is this how you mean?
 
Old 11-30-2009, 02:15 PM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Sorry---what I was referring to was an expanded variable inside a more complex quoted string.

example:
Code:
[mherring@mystical ~]$ vari="she"
[mherring@mystical ~]$ echo $vari
she
[mherring@mystical ~]$ sed 's/$vari/HERE/' words
this
is
a test
the quick brown fox
she sells seashells
[mherring@mystical ~]$ sed "s/$vari/HERE/" words
this
is
a test
the quick brown fox
HERE sells seashells
 
Old 11-30-2009, 02:42 PM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
Quote:
Originally Posted by GrapefruiTgirl View Post
I can leave the backticks, but would like to know what it is about this particular line that's so special..
Puzzling ... it says here that backslashes are handled differently inside backticks but I'm too tired to work out why that results in the symptoms you describe. Goodnight!
 
  


Reply

Tags
backticks, gawk


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] [Ruby on Rails] backticks don't work under rails. bartonski Programming 1 09-08-2009 04:19 PM
getting gawk to operate on a string in a bash script Lordandmaker Linux - Newbie 3 02-26-2007 12:01 PM
Acer TM2420 wireless radio not switching on but driver seems fine in Mandriva 2006 pigdogza Linux - Wireless Networking 2 07-12-2006 11:31 AM
Bash scripting: Nesting backticks ? Deleriux Programming 1 01-04-2004 02:08 PM
bash Shell Programming Curiosity... verbal Programming 3 09-03-2002 10:42 AM


All times are GMT -5. The time now is 05:33 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration