For Programmers: Free Programming Magazines  


Home > Archive > AWK > December 2004 > Re: Passing string to awk









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: Passing string to awk
Joseph

2004-12-24, 3:55 pm

More universal approach to pass any strings in unix is, e.g.

#!/bin/ksh
env_var="New Year"
year="2004"
awk "
BEGIN{
x=\"${env_var}\";
printf(\"msg: %s\n\",x);

year=\"${year}\";
year++;
printf(\"%ld\n\",year);
exit;
}
"

exit 0 #### EOF Script

-Joseph

Patrick TJ McPhee

2004-12-28, 3:55 am

In article <1103911244.795726.221390@f14g2000cwb.googlegroups.com>,
Joseph <jshkolni@hotmail.com> wrote:
% More universal approach to pass any strings in unix is, e.g.

[to put the awk script in double-quotes and escape every ",
$, `, and \.]

I don't really know what you mean by universal, but I don't
think it's well-advised to take this approach. All the escaping
makes things harder to read, and it's quite error-prone. It's
much better to assign values to variables on the awk command-line,
or pass them through the environment.

--

Patrick TJ McPhee
North York Canada
ptjm@interlog.com
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com