Skip to main content
edited body
Source Link
thanasisp
  • 8.5k
  • 2
  • 29
  • 40

why does GREP_COLORS appear not to have a default value?

Because the environment variable GREP_COLORS can be used to override the esistingexisting default colors. It doesn't mean that it must be used.

The GNU grep default colors are defined into grep.c:

/* The color strings used for matched text.
   The user can overwrite them using the deprecated
   environment variable GREP_COLOR or the new GREP_COLORS.  */
static const char *selected_match_color = "01;31";      /* bold red */
static const char *context_match_color  = "01;31";      /* bold red */

/* Other colors.  Defaults look damn good.  */
static const char *filename_color = "35";       /* magenta */
static const char *line_num_color = "32";       /* green */
static const char *byte_num_color = "32";       /* green */
static const char *sep_color      = "36";       /* cyan */
static const char *selected_line_color = "";    /* default color pair */
static const char *context_line_color  = "";    /* default color pair */

and later there is a function parse_grep_colors (void) trying to get a value from GREP_COLORS environment variable. If it's empty or if its syntax is not valid, it will be ignored. For example if you set GREP_COLORS='random text', it will be ignored.

why does GREP_COLORS appear not to have a default value?

Because the environment variable GREP_COLORS can be used to override the esisting default colors. It doesn't mean that it must be used.

The GNU grep default colors are defined into grep.c:

/* The color strings used for matched text.
   The user can overwrite them using the deprecated
   environment variable GREP_COLOR or the new GREP_COLORS.  */
static const char *selected_match_color = "01;31";      /* bold red */
static const char *context_match_color  = "01;31";      /* bold red */

/* Other colors.  Defaults look damn good.  */
static const char *filename_color = "35";       /* magenta */
static const char *line_num_color = "32";       /* green */
static const char *byte_num_color = "32";       /* green */
static const char *sep_color      = "36";       /* cyan */
static const char *selected_line_color = "";    /* default color pair */
static const char *context_line_color  = "";    /* default color pair */

and later there is a function parse_grep_colors (void) trying to get a value from GREP_COLORS environment variable. If it's empty or if its syntax is not valid, it will be ignored. For example if you set GREP_COLORS='random text', it will be ignored.

why does GREP_COLORS appear not to have a default value?

Because the environment variable GREP_COLORS can be used to override the existing default colors. It doesn't mean that it must be used.

The GNU grep default colors are defined into grep.c:

/* The color strings used for matched text.
   The user can overwrite them using the deprecated
   environment variable GREP_COLOR or the new GREP_COLORS.  */
static const char *selected_match_color = "01;31";      /* bold red */
static const char *context_match_color  = "01;31";      /* bold red */

/* Other colors.  Defaults look damn good.  */
static const char *filename_color = "35";       /* magenta */
static const char *line_num_color = "32";       /* green */
static const char *byte_num_color = "32";       /* green */
static const char *sep_color      = "36";       /* cyan */
static const char *selected_line_color = "";    /* default color pair */
static const char *context_line_color  = "";    /* default color pair */

and later there is a function parse_grep_colors (void) trying to get a value from GREP_COLORS environment variable. If it's empty or if its syntax is not valid, it will be ignored. For example if you set GREP_COLORS='random text', it will be ignored.

Source Link
thanasisp
  • 8.5k
  • 2
  • 29
  • 40

why does GREP_COLORS appear not to have a default value?

Because the environment variable GREP_COLORS can be used to override the esisting default colors. It doesn't mean that it must be used.

The GNU grep default colors are defined into grep.c:

/* The color strings used for matched text.
   The user can overwrite them using the deprecated
   environment variable GREP_COLOR or the new GREP_COLORS.  */
static const char *selected_match_color = "01;31";      /* bold red */
static const char *context_match_color  = "01;31";      /* bold red */

/* Other colors.  Defaults look damn good.  */
static const char *filename_color = "35";       /* magenta */
static const char *line_num_color = "32";       /* green */
static const char *byte_num_color = "32";       /* green */
static const char *sep_color      = "36";       /* cyan */
static const char *selected_line_color = "";    /* default color pair */
static const char *context_line_color  = "";    /* default color pair */

and later there is a function parse_grep_colors (void) trying to get a value from GREP_COLORS environment variable. If it's empty or if its syntax is not valid, it will be ignored. For example if you set GREP_COLORS='random text', it will be ignored.