LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 02-22-2010, 08:01 AM   #1
rohini_sharma
LQ Newbie
 
Registered: Feb 2010
Posts: 1

Rep: Reputation: 0
Unhappy Shell variable in awk script


I need to export some Varibales in Shell like (KSH )

export CORE=1
export DODDY=0

then I need to call these variables in the awk

#!/bin/awk -f

BEGIN {

if ( $CORE ~ "1" ) {

print "Core is right one "

}

But awk doesnot understand the variables and I am not getting the right results

Can you help me out

Thanks
Rohini
 
Old 02-22-2010, 08:15 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Try awk's -v option
 
Old 02-22-2010, 08:17 AM   #3
irmin
Member
 
Registered: Jan 2010
Location: the universe
Distribution: Slackware (modified), Slackware64 (modified), openSuSE (modified)
Posts: 342

Rep: Reputation: 62
In awk the environment variables can be accessed through the associative array ENVIRON:
Code:
#!/bin/awk -f

BEGIN {

if ( ENVIRON["CORE"] ~ "1" ) {

print "Core is right one "

}
 
Old 02-22-2010, 08:32 AM   #4
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quick glance:

The -f flag says to get code from a file, but you have the code inline.

"~" means "ERE match". Why not just use "==" ?
 
  


Reply



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
Trouble storing a variable in a shell script after awk output uncle-c Linux - Newbie 3 02-08-2010 07:13 AM
awk and shell variable markux Linux - Server 6 01-19-2009 03:54 AM
passing awk output to $variable for shell script? NewnanNOC Programming 3 10-23-2008 02:08 PM
How to share variable values between shell and awk? realos Programming 1 12-16-2006 10:15 PM
Accessing Shell variable in awk script dileepkk Linux - General 1 10-07-2004 07:47 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:45 PM.

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
Open Source Consulting | Domain Registration