Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers 2

Try

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

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

share|improve this answer
    
Thanks, but that also doesn't work. –  superuser Oct 12 '12 at 18:35
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.