Reputation: 4099
The following piece of awk code works fine if I use eval builtin
var='$1,$2'
ps | eval "awk '{print $var}'"
But when I try to knock off eval and use awk variable as substitute then I am not getting the expected result
ps | awk -v v1=$var '{print v1}' # output is $1,$2
ps | awk -v v1=`echo $var` '{print v1}' # output is same as above
ps | awk -v v1=$var '{print $v1}' # output is all the fields of ps command
ps | eval "awk -v v1=$var '{print v1}'" # output is column of comma
How to get the desire output without using eval?
Upvotes: 2
Views: 102