2

To set my default options for grep (from MSYS in Win7) to ignore object files and specific dirs, I exported GREP_OPTIONS to ~/.profile as follows:

export GREP_OPTIONS='--exclude=*.{o,obj,pyc} --exclude-dir={.git,_Output}'
export GREP_COLOR='1;32'

Even after restarting the shell for my .profile to take effect, my call to grep still searches object files. However, the GREP_COLOR variable seems to work. I even tried explicitly setting my options in the same shell before executing grep:

$ grep --version
GNU grep 2.5.4

Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ export GREP_OPTIONS='--exclude=*.{o,obj,pyc} --exclude-dir={.git,_Output}'
$ echo $GREP_OPTIONS
--exclude=*.{o,obj,pyc} --exclude-dir={.git,_Output}
$ grep $GREP_OPTIONS -r foo .
grep: ./bar.o: Permission denied
./baz.c:My foo text
$ grep --exclude=*.{o,obj,pyc} --exclude-dir={.git,_Output} -r foo .
./baz.c:My foo text

How do I get grep to automatically use GREP_OPTIONS from ~/.profile?

2 Answers 2

0

Try

export GREP_OPTIONS='--exclude="*.{o,obj,pyc}" --exclude-dir={.git,_Output}'

i.e., enclosing the --exclude filename pattern in (double) quotes.

1
  • Thanks, but that also doesn't work.
    – tony19
    Oct 12, 2012 at 18:35
0

Try putting the variables in .profile, along with a line that says something like the following:

alias grep='grep $GREP_OPTIONS'

That just might fix it.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .