[mdlug] Bash back quotes do not work with backslash

Michael Corral micorral at comcast.net
Fri Jun 29 15:21:37 EDT 2012


2012-06-29, Monsieur R KANNAN a ecrit:
> 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 ^'\$'`

If you use backticks then double-escape the $ sign:

test=`fgrep -i AMLSNCPU WK_sol_103_amls.dat | grep -m 1 -v ^'\\$'`

It's better to use test=$(...) instead, no double-escape required.

Michael



More information about the mdlug mailing list