Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Awk > Re: How to pass...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 5 of 10 Topic 2218 of 2236
Post > Topic >>

Re: How to pass UNIX variable into awk?

by gazelle@[EMAIL PROTECTED] (Kenny McCormack) Apr 8, 2008 at 11:39 PM

In article <47FBFE15.2010500@[EMAIL PROTECTED]
>,
Ed Morton  <morton@[EMAIL PROTECTED]
> wrote:
....
>Yes, it is:
>
>$ var="#"
>$ awk 'BEGIN{ print '"$var"' }'
>awk: cmd. line:1: BEGIN{ print # }
>awk: cmd. line:1:              ^ syntax error
>$ awk -v var="$var" 'BEGIN{ print var }'
>#

You make it entirely too easy for me:

sh-3.1$ var="#"
sh-3.1$ action="print"
sh-3.1$ gawk 'BEGIN {'$action' "'$var'"}'
#
sh-3.1$ 

Now, to be fair, I'm not saying there isn't some total corner case that
involves the variable having the value "rm -rf /;echo foo on you | Mail
prez@[EMAIL PROTECTED]
" or something like that.  I think the shell nuts may
well come up with something, but I do think that for all normal cases,
the risk is the same using either the "hopping back and forth" method
and using the "var=" form.

But I don't really care about any of that; the point is that for
real-world day-to-day use, this is method is good enough.  You are, of
course, free to disagree with that.




 10 Posts in Topic:
How to pass UNIX variable into awk?
RC <raymond.chui@[EMAI  2008-04-08 10:43:05 
Re: How to pass UNIX variable into awk?
RC <raymond.chui@[EMAI  2008-04-08 10:57:32 
Re: How to pass UNIX variable into awk?
gazelle@[EMAIL PROTECTED]  2008-04-08 15:00:24 
Re: How to pass UNIX variable into awk?
Ed Morton <morton@[EMA  2008-04-08 18:21:57 
Re: How to pass UNIX variable into awk?
gazelle@[EMAIL PROTECTED]  2008-04-08 23:39:23 
Re: How to pass UNIX variable into awk?
Ed Morton <morton@[EMA  2008-04-08 19:00:06 
Re: How to pass UNIX variable into awk?
Ed Morton <morton@[EMA  2008-04-08 18:18:21 
Re: How to pass UNIX variable into awk?
pk <pk@[EMAIL PROTECTE  2008-04-08 17:19:25 
Re: How to pass UNIX variable into awk?
Janis <janis_papanagno  2008-04-08 08:09:54 
Re: How to pass UNIX variable into awk?
pk <pk@[EMAIL PROTECTE  2008-04-08 17:31:07 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri May 16 23:26:37 CDT 2008.