[mdlug] Bash back quotes do not work with backslash
Aaron Kulkis
akulkis00 at gmail.com
Fri Jun 29 16:26:14 EDT 2012
R KANNAN wrote:
> Bash Gurus,
>
> I am trying to look for a string in a file on lines which don't start with
> a '$' and use that line for further processing in bash.
>
>
> Somehow setting a variable from a command (using back quote) gives
> different results than the command itself.
>
>
>
> [t7689rk at lh070p8x WK]$ fgrep -i AMLSNCPU WK_sol_103_amls.dat | grep -m 1 -v
> ^'\$'
>
> PARAM,AMLSNCPU,4
>
> [t7689rk at lh070p8x WK]$ test=`fgrep -i AMLSNCPU WK_sol_103_amls.dat | grep
> -m 1 -v ^'\$'`
>
> [t7689rk at lh070p8x WK]$ echo $test
>
> $ Use AMLSNCPU=4
>
>
>
> Looks like the escaping of $ within back quotes is not working.
>
>
The alternative to `pipeline` is $(pipeline)
so try this:
test=$(fgrep -i AMLSNCPU WK_sol_103_amls.dat | grep -m 1 -v ^'\$')
$(pipeline) means
run pipeline in a subshell (), and
return the output as a string $
More information about the mdlug
mailing list