Subject: bug#55641: Using colours with grep

From: Gary Johnson <[email-masked]>
Date: Sat, 28 May 2022 11:38:26 -0700

On 2022-05-28, goncholden wrote:
> I was trying to change the colours used for matching temporarily.
> But GREP_COLORS is global in nature.

An environment variable such as GREP_COLORS set by itself on the
command line persists in the environment after it has been set.  An
environment variable set on the same line as a command, such as

    GREP_COLORS='ms=01;32' grep this_pattern that_file

affects only the environment of that command, persists only for the
duration of that command, and does not affect the shell's
environment.

That may not be completely accurate, but it's close.

So, setting GREP_COLORS on the grep command line as above will
affect only that command and will not affect the "global" setting,
as you put it.

See the ENVIRONMENT section of the bash(1) man page.

Regards,
Gary