Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 <>
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}'
--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


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. – tony19 Oct 12 '12 at 18:35

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

You must log in to answer this question.

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