Maybe you should ask a different question. Why are you defining options to be applied to every invocation of grep you make in your .bashrc file if you don't want those options to be applied every time you invoke grep ?
Have you considered defining an alias for grep that includes the options you want to apply only when grep is invoked interactively?
if i did an alias, it could easily be stomped on by another shell or script running or if i used a different grep like BSD, it would probably choke on an alias.
i'm really looking for something simple that would just strip out the '^[K' formatting characters like with
echo
or
printf
something that recognizes these as not to print or is so dumb that it ignores anything but the displayed string without attributes so that when i pipe something to my script file i don't have turn off or unset switches
You can't have it both ways. If you want to make EVERY invocation of grep use the flags you are setting in GREP_OPTIONS , you are all set. But, as you have seen, that breaks scripts that depend on grep to do what the standards say grep is supposed to do.
If you want interactive invocations of grep to use a specific set of options, use an alias . If you want interactive invocations of grep to use a specific set of options if, and only if, you are running on a Linux system, define an alias for grep in your .bashrc if, and only if, uname indicates that you're starting bash on a Linux system.
Otherwise, I think you have two options:
rewrite every shell script you use (provided by you or anyone else) that uses grep ,
OR
get rid of the definition of GREP_OPTIONS in your .bashrc and add a new utility ( mygrep ) in your bin directory ( $HOME/bin/mygrep ) that contains something like:
that you install on Linux systems and on non-Linux systems install a symlink $HOME/bin/mygrep that points to wherever grep is located on that system and learn to use mygrep instead of grep whenever you use it interactively.
Not even when the option-argument is always (as in --color=always )? I don't have a GNU grep to test but I haven't seen where the GNU man page states any exceptions to always in the above case. (Maybe the "on the terminal" in that section of the description means that --color is ignored when output isn't directed to a terminal device, but it doesn't clearly state that behavior.)
I have tested different versions of GNU grep.
Don, you are right, the --color=always puts some default color codes even if the output is not a terminal.
Correct is --color=auto .
Therefore, the .bashrc/.profile should have the environment