Question

I'm trying to find where two variables 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?

Was it helpful?

Solution

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"

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top