Breaking Grep

While rummaging around the grep man page i stumbled on something I’d never noticed before; GREP_OPTIONS. This environmental variable does pretty much what you’d expect, once set it passes the options you specified to each and every invocation of grep that runs with the variable still in scope.

While I’m not aware of any real positive usages for this something slightly less wholesome crossed my mind. If you set ‘GREP_OPTIONS=-v’ then every run would return the lines NOT matching your criteria, -v is an absolute switch rather than a toggle one so its not possible to reverse it with another -v. This would be a seriously annoying problem to track, you’d have to get lucky and notice it in the output of ‘set’ or a similar command.

Not that I’d ever think of doing that of course ;)