开发者

command-line grep for a string with '$' in it?

开发者 https://www.devze.com 2022-12-09 21:53 出处:网络
I\'m trying to find where two var开发者_开发百科iables are being concatenated in a directory of scripts, but when I try the following:

I'm trying to find where two var开发者_开发百科iables are being concatenated in a directory of scripts, but when I try the following:

grep -lire "$DATA_PATH . $AWARDS_YEAR" *

I get "undefined variable" errors...

I thought I could escape the $s by using:

grep -lire "\$DATA_PATH . \$AWARDS_YEAR" *

But I get the same error - so, how do you grep for strings with $s in?


Tcsh is a little different about variables than the usual shells, and it's the default on FreeBSD.

So, just use single quotes, '$VAR', or escape the $ outside of the quotes: \$"VAR"


Put it in single quotes, with the escaping slash:

grep -lire '\$DATA_PATH . \$AWARDS_YEAR' *

Also note, that the dot (.) is a regex character. If you don't want it to be, escape it, too (or don't use the -e option).

Here's a nice reference with more general info.

0

精彩评论

暂无评论...
验证码 换一张
取 消