awk does not exit and receives shell variables for you, you must pass them as awk variables:
pax> export x=XX pax> export y=YY pax> awk 'BEGIN{print x "_" y}' _ pax> awk -vx=$x -vy=$y 'BEGIN{print x "_" y}' XX_YY
There is another way to do this using double quotes instead of single quotes (so bash replaces values ββbefore awk sees them), but then you need to start escaping the $ characters and all sorts of other things in your awk command:
pax> awk "BEGIN {print \"${x}_${y}\"}" XX_YY
I prefer to use explicit variable creation.
By the way, there is another solution to your previous related question here that should work.
paxdiablo
source share