Ignores --color=always in GREP_OPTIONS

Bug #921154 reported by Jani Uusitalo
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
grep (Ubuntu)
Invalid
Undecided
Unassigned

Bug Description

(Doing this in reverse order, as I think the steps are best represented by what I actually type in.)

Premise:
I'm a newbie who tries to do the nasty and make grep output always colored using GREP_OPTIONS. I have a file called test, with numbers 1-9 each on its own line.

What I expect to happen:
For all the numbers I grep from my file except 2 to be colored.

What actually happens:
Neither when preceding the grep with GREP_OPTIONS when I grep 4, nor when GREP_OPTIONS is exported prior to grepping 5, is the resulting output colored.

What does work:
Passing --color=always as a genuine grep parameter. Passing (for example) -V in GREP_OPTIONS either on the same line or exported.

Additional notes:
This crippling might be some kind of a safety measure to prevent all the breakage that doing what I'm attempting to do risks inflicting on the system. But I've not been able to find any documentation about such a design decision having been made, and in contrast, the man page to my understanding implies that this should, in fact, work.

Steps to reproduce:

jani@saegusa:~$ printenv | grep -i grep
jani@saegusa:~$ grep 1 test # colored
1
jani@saegusa:~$ grep 2 test | cat # not colored
2
jani@saegusa:~$ grep --color=always 3 test | cat # colored
3
jani@saegusa:~$ GREP_OPTIONS='--color=always' grep 4 test | cat # NOT colored!
4
jani@saegusa:~$ export GREP_OPTIONS='--color=always'
jani@saegusa:~$ grep 5 test | cat # NOT colored!
5
jani@saegusa:~$ export GREP_OPTIONS='-V'
jani@saegusa:~$ grep 6 test | cat # control
grep (GNU grep) 2.10
Copyright © 2011 Free Software Foundation, Inc.
Lisenssi GPLv3+: GNU GPL versio 3 tai myöhäisempi <http://gnu.org/licenses/gpl.html>
Tämä on vapaa ohjelma: voit vapaasti muuttaa ja jakaa sitä edelleen.
Ohjelmalla EI OLE TAKUUTA siinä laajuudessa kuin laki sen sallii.

Tekijät: Mike Haertel ja muut, katso <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.

ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: grep 2.10-1
ProcVersionSignature: Ubuntu 3.2.0-10.17-generic 3.2.1
Uname: Linux 3.2.0-10-generic x86_64
ApportVersion: 1.91-0ubuntu1
Architecture: amd64
CheckboxSubmission: 09ae689090491ca53449589269e4bfd8
CheckboxSystem: edda5d4f616ca792bf437989cb597002
Date: Tue Jan 24 20:45:31 2012
EcryptfsInUse: Yes
InstallationMedia: Ubuntu 9.10 "Karmic Koala" - Release amd64 (20091027)
SourcePackage: grep
UpgradeStatus: Upgraded to precise on 2012-01-17 (7 days ago)

Revision history for this message
Jani Uusitalo (uusijani) wrote :
Revision history for this message
Marcel Stimberg (marcelstimberg) wrote :

Thank you for taking the time to report this bug and helping to make Ubuntu better.

It took me a while to find this out -- it really looks weird! The solution is quite simple, though: In the standard ~/.bashrc you find the following line:
alias grep='grep --color=auto'

GREP_OPTIONS are *prepended* to all other options. With the alias definition, your --color option gets overridden by --color=auto every time. Deleting this line from .bashrc or using "unalias grep" should solve the issue for you. If it does not, please feel free to reopen this bug report by setting the status back to "New".

Changed in grep (Ubuntu):
status: New → Invalid
Revision history for this message
Jani Uusitalo (uusijani) wrote :

Hi Marcel. You're absolutely right: it's the .bashrc alias that caused this. Such a simple yet elusive solution, my compliments for catching it! :)

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.