Avainsanana grep

Such a simple yet elusive solution

29. tammikuuta 2012 klo 18.20
Sijainti: Vianhallintajärjestelmät: Launchpad
Avainsanat: grep

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! :)

Vastaa viestiin sen kontekstissa (Launchpad)

Ignores –color=always in GREP_OPTIONS

24. tammikuuta 2012 klo 21.57
Sijainti: Vianhallintajärjestelmät: Launchpad
Avainsanat: grep

(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
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 .

Vastaa viestiin sen kontekstissa (Launchpad)