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

I was messing around with grep and put this in my .zshenv:

export GREP_OPTIONS="--color=auto"
export GREP_COLORS='mt=1;34'

I was bonking my head on the keyboard and changing GREP_COLORS around for a minute trying to figure out why the folder colors were working, but the matching text wasn't.

I was doing this:

$ grep -R -n -i -e "functionFoo\(" --include=*.cs --exclude-dir=Logs *

The line number and file names were set with the default colors, but the matching text wasn't.

After spending way too much time, I thought to do this:

$ grep -R -n -e "functionFoo\(" --include=*.cs --exclude-dir=Logs *

(I removed the -i option.) That's all it took to get the matching text to correctly show up in bold blue. This is a Cygwin on Vista setup, with rxvt running zsh.

Any idea why grep colors would break on specifying a case-insensitive match?

Update: Under cygwin 1.7, it's a little bit better - case insensitive search works correctly, but it only highlights the word that matches the expression exactly. In other words, "FunctionFoo" highlights "FunctionFoo" but not "functionFoo" and vice versa. Probably a grep issue so I'll be submitting it to that list.

share|improve this question
This works for me using GNU grep 2.5.4 – innaM Nov 20 '09 at 20:38
works for me, GNU grep 2.5.3, under bash on debian lenny and on cygwin. what version grep? what system? – quack quixote Nov 20 '09 at 21:00
GNU grep 2.5.3, and CYGWIN_NT-6.0-WOW64 AAF 1.5.25(0.156/4/2) 2008-06-12 19:34 i686 Cygwin is the uname -a output. – emptyset Nov 20 '09 at 21:37
i've got the same buildtime on my cygwin but it's CYGWIN_NT-5.1 (on winXP here). my best guess is you're hitting some bug in cygwin .. likely some difference in XP-cmd.exe vs Vista-cmd.exe that hasn't been addressed properly in cygwin's terminfo/termcap. you should probably drop a bugreport to cygwin about it. – quack quixote Nov 21 '09 at 0:24

This is not related to Cygwin but to grep. You need to set the locale environment variables in your shell, like LANG.

Taken from the grep(1) manual:

The locale for category LC_foo is specified by examining the three environment variables LC_ALL, LC_foo, LANG, in that order. The first of these variables that is set specifies the locale. For example, if LC_ALL is not set, but LC_MESSAGES is set to pt_BR, then the Brazilian Portuguese locale is used for the LC_MESSAGES category. The C locale is used if none of these environment variables are set, if the locale catalog is not installed, or if grep was not compiled with national language support (NLS).

Try for example:

LANG=en_US.UTF-8 grep -R -n -i -e "functionFoo\(" --include=*.cs --exclude-dir=Logs *

That should fix your problem, and works for me with GNU grep 2.5.4 and bash 3.2.48(1)-release.

share|improve this answer
Almost works. When I set the shell variable inline like that, it works if LANG is currently set to C.UTF-8 (default). When I edited my .zprofile to include the line export LANG=en_US.UTF-8, then it ceases to work (even setting LANG inline). – emptyset May 3 '10 at 21:54
What version of zsh are you using ? – sirdharma May 5 '10 at 16:50

I had this same problem using Msys MinGW. I didn't find a way to resolve it so ended up using:

ack -i PATTERN

which does colors and case insensitivity correctly.

share|improve this answer

You must log in to answer this question.

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