LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-30-2012, 03:10 AM   #1
vicky007aggrwal
Member
 
Registered: Aug 2012
Posts: 95

Rep: Reputation: Disabled
awk command issue


Any idea on hwo to knock out the below error


root="/webroot"
echo $root | awk -v r=$root '{ print "shell root value - " r}'
awk: syntax error near line 1
awk: bailing out near line 1
 
Old 10-30-2012, 03:25 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
The above works when using gawk and bash:
Code:
$ root="/webroot"
$ echo $root
/webroot
$ echo $root | awk -v r=$root '{ print "shell root value - " r}'
shell root value - /webroot
Which awk are you using: awk --version or ls -l $(which awk)

And which shell: grep $(id -u) /etc/passwd
 
1 members found this post helpful.
Old 10-30-2012, 12:36 PM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,424

Rep: Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823Reputation: 2823
My question would be ... what is the purpose of the script?

The echo is pointless. Just place BEGIN before the braces.
 
Old 10-30-2012, 01:50 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958Reputation: 1958
For that matter, what's wrong with this?

Code:
echo "shell root value - $root"
Unless you have some other, more complex need for awk that you didn't post?
 
Old 10-31-2012, 02:22 PM   #5
vicky007aggrwal
Member
 
Registered: Aug 2012
Posts: 95

Original Poster
Rep: Reputation: Disabled
thanks david ,i just put a random example to seek advise.. related to it i have one complex expression

anyway Thanks a lot all.. my issue resolved
 
  


Reply


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
Awk issue !! PMP Programming 8 06-08-2010 03:20 AM
awk variable issue cdestiny Linux - General 5 03-11-2010 12:26 AM
awk command toaravind Linux - General 5 07-02-2008 02:25 AM
shell command using awk fields inside awk one71 Programming 6 06-26-2008 05:11 PM
the 'awk' command. iconicmoronic Linux - Newbie 2 04-08-2007 01:29 AM


All times are GMT -5. The time now is 07:54 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration