Why does this work:
This
var=hello
myvar=`echo hello hi | awk "{ if (\\\$1 == \"$var\" ) print \\\$2; }"`
echo $myvar
gives
hi
But this does not?
This
var=hello
echo hello hi | awk "{ if (\\\$1 == \"$var\" ) print \\\$2; }"
gives
awk: cmd. line:1: Unexpected token
I am using
GNU bash, version 4.1.5(1)-release (i486-pc-linux-gnu)
on
Linux 2.6.32-34-generic-pae #77-Ubuntu SMP Tue Sep 13 21:16:18 UTC 2011 i686 GNU/Linux
backslash not last character on line. Tryset -xbefore andset +xafter your commands to see a trace of how things work such as variable substitution and backslash evaluation. - Dennis Williamson