Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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

I am trying to get my regex highlighted on mac using terminal. I have put this is my .profile:

export GREP_COLOR='1;30;40'

Nothing changes, so I added the same to my bash.profile still nothing, restarted the machine nothing. When I am:

egrep --color=auto ".*\W blah blah "

then it lights up some yellow color but I wondered if I had done something wrong in my .profile or bash_profile.

Any help would be good: snow leopard, with just plain old terminal :-)

share|improve this question
Isn't GREP_COLOR deprecated? Anyways grep --color should highlight matches in the default color, without any need for environment variables. – jw013 Mar 23 '12 at 0:07

This worked on my snow leopard machine. Try just copying and pasting the text in your terminal and seeing if grep shows the desired behavior. If it does, then the problem is you're not adding it to the right dotfile. What shell are you using? The dotfile you should add it to depends on the shell you use.

export GREP_OPTIONS='--color=auto'
export GREP_COLOR='1;30;40'

Also, try running printenv to see what environmental variables you already have set and see if any grep options are already.

share|improve this answer
excellent!!! thank you!! much better than setting up an alias! – cwd Apr 26 '12 at 13:44
Weird. I was going to vote this answer up, but it didn't work for me using Terminal on Snow Leopard. It turned the matched text into all-black boxes. – Old Pro Apr 27 '12 at 4:36
@OldPro - I would recommend actually using export GREP_COLOR='1;35;40' because 35 is cyan and 30 is gray- 40 is black background, so it looks dark. But yes it works! :) – cwd Apr 27 '12 at 18:39

I don't think Snow Leopard's default setting is to use color for grep. I've had success on my OS X box with adding a line like alias grep=grep --color=always in my .bashrc to ensure consistent highlighting.

share|improve this answer
--color=always can be a problem if grep's output is piped to another command. --color=auto will emit the control characters for only when the output is directly displayed on the terminal – Gowtham Mar 23 '12 at 7:23
Good call! Thanks for the correction. – noffle Mar 23 '12 at 14:24

It's not bash.profile nor bash_profile, it's .bash_profile.

As for the colors on your Mac, just put this in your ~/.bash_profile:

export GREP_OPTIONS='--color=auto'
export GREP_COLOR='1;30;40'

Be sure to use .bash_profile in your home directory (~/).

share|improve this answer

Your Answer


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.