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.


|