LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Manjaro (https://www.linuxquestions.org/questions/manjaro-119/)
-   -   "GREP_COLORS=" cannot work so long as preceded by sudo (https://www.linuxquestions.org/questions/manjaro-119/grep_colors%3D-cannot-work-so-long-as-preceded-by-sudo-4175701780/)

BudiKusasi 10-10-2021 07:30 AM

"GREP_COLORS=" cannot work so long as preceded by sudo
 
Why "GREP_COLORS=" set cannot work if grep family, i.e. more actually pcre2grep, preceded by sudo ?

though fact is other Linux, i.e. MX, simply go working
please help out to work here too

shruggy 10-10-2021 08:19 AM

Most probably, you have defined an alias somewhere in your shell startup files for regular user. Something along the lines
Code:

alias pcre2grep='pcre2grep --color=auto'
This alias is not defined for root. Compare the output of
Code:

alias
and
Code:

sudo alias
Same goes for the environment variable GREP_COLORS. By default, sudo sanitizes most of the environment. GREP_COLORS set for the regular user won't be seen by root unless included in the env_keep list.

This is actually the case where cat abuse otherwise known as UUOC might make sense:
Code:

sudo cat file_accessible_only_by_root|pcre2grep RE
Or just specify the --color option explicitly (this will use default colors though):
Code:

sudo pcre2grep --color RE file_accessible_only_by_root

BudiKusasi 10-10-2021 01:40 PM

EXCELLENT
Thanks, more importantly must God reward you..


All times are GMT -5. The time now is 06:33 AM.