2 edited tags; edited tags
| link
1
source | link

In bash, grep for a line beginning with \, and assign the result using backticks

In bash, I'm trying to grep a file for a line beginning with a \, and return the result using backticks.

For example:

echo \\Hello > myFile
out=`cat myFile | grep '^\\Hello'`
echo $out

returns nothing, even though

cat myFile | grep '^\\Hello'

returns, as epected.

\Hello

This seems extremely odd shell behavior. In particular, the anologous command sequence in tcsh does what one would expect:

set out=`cat myFile | grep '^\\Hello'`; echo $out

returns

\Hello

Could somebody explain what's going on please? Thanks