grep: Environment Variables
1
1 2.2 Environment Variables
1 =========================
1
1 The behavior of ‘grep’ is affected by the following environment
1 variables.
1
1 The locale for category ‘LC_FOO’ is specified by examining the three
1 environment variables ‘LC_ALL’, ‘LC_FOO’, and ‘LANG’, in that order.
1 The first of these variables that is set specifies the locale. For
1 example, if ‘LC_ALL’ is not set, but ‘LC_COLLATE’ is set to ‘pt_BR’,
1 then the Brazilian Portuguese locale is used for the ‘LC_COLLATE’
1 category. As a special case for ‘LC_MESSAGES’ only, the environment
1 variable ‘LANGUAGE’ can contain a colon-separated list of languages that
1 overrides the three environment variables that ordinarily specify the
1 ‘LC_MESSAGES’ category. The ‘C’ locale is used if none of these
1 environment variables are set, if the locale catalog is not installed,
1 or if ‘grep’ was not compiled with national language support (NLS). The
1 shell command ‘locale -a’ lists locales that are currently available.
1
1 Many of the environment variables in the following list let you
1 control highlighting using Select Graphic Rendition (SGR) commands
1 interpreted by the terminal or terminal emulator. (See the section in
1 the documentation of your text terminal for permitted values and their
1 meanings as character attributes.) These substring values are integers
1 in decimal representation and can be concatenated with semicolons.
1 ‘grep’ takes care of assembling the result into a complete SGR sequence
1 (‘\33[’...‘m’). Common values to concatenate include ‘1’ for bold, ‘4’
1 for underline, ‘5’ for blink, ‘7’ for inverse, ‘39’ for default
1 foreground color, ‘30’ to ‘37’ for foreground colors, ‘90’ to ‘97’ for
1 16-color mode foreground colors, ‘38;5;0’ to ‘38;5;255’ for 88-color and
1 256-color modes foreground colors, ‘49’ for default background color,
1 ‘40’ to ‘47’ for background colors, ‘100’ to ‘107’ for 16-color mode
1 background colors, and ‘48;5;0’ to ‘48;5;255’ for 88-color and 256-color
1 modes background colors.
1
1 The two-letter names used in the ‘GREP_COLORS’ environment variable
1 (and some of the others) refer to terminal “capabilities,” the ability
1 of a terminal to highlight text, or change its color, and so on. These
1 capabilities are stored in an online database and accessed by the
1 ‘terminfo’ library.
1
1 ‘GREP_OPTIONS’
1 This variable specifies default options to be placed in front of
1 any explicit options. As this causes problems when writing
1 portable scripts, this feature will be removed in a future release
1 of ‘grep’, and ‘grep’ warns if it is used. Please use an alias or
1 script instead. For example, if ‘grep’ is in the directory
1 ‘/usr/bin’ you can prepend ‘$HOME/bin’ to your ‘PATH’ and create an
1 executable script ‘$HOME/bin/grep’ containing the following:
1
1 #! /bin/sh
1 export PATH=/usr/bin
1 exec grep --color=auto --devices=skip "$@"
1
1 ‘GREP_COLOR’
1 This variable specifies the color used to highlight matched
1 (non-empty) text. It is deprecated in favor of ‘GREP_COLORS’, but
1 still supported. The ‘mt’, ‘ms’, and ‘mc’ capabilities of
1 ‘GREP_COLORS’ have priority over it. It can only specify the color
1 used to highlight the matching non-empty text in any matching line
1 (a selected line when the ‘-v’ command-line option is omitted, or a
1 context line when ‘-v’ is specified). The default is ‘01;31’,
1 which means a bold red foreground text on the terminal’s default
1 background.
1
1 ‘GREP_COLORS’
1 This variable specifies the colors and other attributes used to
1 highlight various parts of the output. Its value is a
1 colon-separated list of ‘terminfo’ capabilities that defaults to
1 ‘ms=01;31:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36’ with the ‘rv’
1 and ‘ne’ boolean capabilities omitted (i.e., false). Supported
1 capabilities are as follows.
1
1 ‘sl=’
1 SGR substring for whole selected lines (i.e., matching lines
1 when the ‘-v’ command-line option is omitted, or non-matching
1 lines when ‘-v’ is specified). If however the boolean ‘rv’
1 capability and the ‘-v’ command-line option are both
1 specified, it applies to context matching lines instead. The
1 default is empty (i.e., the terminal’s default color pair).
1
1 ‘cx=’
1 SGR substring for whole context lines (i.e., non-matching
1 lines when the ‘-v’ command-line option is omitted, or
1 matching lines when ‘-v’ is specified). If however the
1 boolean ‘rv’ capability and the ‘-v’ command-line option are
1 both specified, it applies to selected non-matching lines
1 instead. The default is empty (i.e., the terminal’s default
1 color pair).
1
1 ‘rv’
1 Boolean value that reverses (swaps) the meanings of the ‘sl=’
1 and ‘cx=’ capabilities when the ‘-v’ command-line option is
1 specified. The default is false (i.e., the capability is
1 omitted).
1
1 ‘mt=01;31’
1 SGR substring for matching non-empty text in any matching line
1 (i.e., a selected line when the ‘-v’ command-line option is
1 omitted, or a context line when ‘-v’ is specified). Setting
1 this is equivalent to setting both ‘ms=’ and ‘mc=’ at once to
1 the same value. The default is a bold red text foreground
1 over the current line background.
1
1 ‘ms=01;31’
1 SGR substring for matching non-empty text in a selected line.
1 (This is used only when the ‘-v’ command-line option is
1 omitted.) The effect of the ‘sl=’ (or ‘cx=’ if ‘rv’)
1 capability remains active when this takes effect. The default
1 is a bold red text foreground over the current line
1 background.
1
1 ‘mc=01;31’
1 SGR substring for matching non-empty text in a context line.
1 (This is used only when the ‘-v’ command-line option is
1 specified.) The effect of the ‘cx=’ (or ‘sl=’ if ‘rv’)
1 capability remains active when this takes effect. The default
1 is a bold red text foreground over the current line
1 background.
1
1 ‘fn=35’
1 SGR substring for file names prefixing any content line. The
1 default is a magenta text foreground over the terminal’s
1 default background.
1
1 ‘ln=32’
1 SGR substring for line numbers prefixing any content line.
1 The default is a green text foreground over the terminal’s
1 default background.
1
1 ‘bn=32’
1 SGR substring for byte offsets prefixing any content line.
1 The default is a green text foreground over the terminal’s
1 default background.
1
1 ‘se=36’
1 SGR substring for separators that are inserted between
1 selected line fields (‘:’), between context line fields (‘-’),
1 and between groups of adjacent lines when nonzero context is
1 specified (‘--’). The default is a cyan text foreground over
1 the terminal’s default background.
1
1 ‘ne’
1 Boolean value that prevents clearing to the end of line using
1 Erase in Line (EL) to Right (‘\33[K’) each time a colorized
1 item ends. This is needed on terminals on which EL is not
1 supported. It is otherwise useful on terminals for which the
1 ‘back_color_erase’ (‘bce’) boolean ‘terminfo’ capability does
1 not apply, when the chosen highlight colors do not affect the
1 background, or when EL is too slow or causes too much flicker.
1 The default is false (i.e., the capability is omitted).
1
1 Note that boolean capabilities have no ‘=’... part. They are
1 omitted (i.e., false) by default and become true when specified.
1
1 ‘LC_ALL’
1 ‘LC_COLLATE’
1 ‘LANG’
1 These variables specify the locale for the ‘LC_COLLATE’ category,
1 which might affect how range expressions like ‘[a-z]’ are
1 interpreted.
1
1 ‘LC_ALL’
1 ‘LC_CTYPE’
1 ‘LANG’
1 These variables specify the locale for the ‘LC_CTYPE’ category,
1 which determines the type of characters, e.g., which characters are
1 whitespace. This category also determines the character encoding,
1 that is, whether text is encoded in UTF-8, ASCII, or some other
1 encoding. In the ‘C’ or ‘POSIX’ locale, all characters are encoded
1 as a single byte and every byte is a valid character.
1
1 ‘LANGUAGE’
1 ‘LC_ALL’
1 ‘LC_MESSAGES’
1 ‘LANG’
1 These variables specify the locale for the ‘LC_MESSAGES’ category,
1 which determines the language that ‘grep’ uses for messages. The
1 default ‘C’ locale uses American English messages.
1
1 ‘POSIXLY_CORRECT’
1 If set, ‘grep’ behaves as POSIX requires; otherwise, ‘grep’ behaves
1 more like other GNU programs. POSIX requires that options that
1 follow file names must be treated as file names; by default, such
1 options are permuted to the front of the operand list and are
1 treated as options. Also, ‘POSIXLY_CORRECT’ disables special
11 handling of an invalid bracket expression. ⇒
invalid-bracket-expr.
1
1 ‘_N_GNU_nonoption_argv_flags_’
1 (Here ‘N’ is ‘grep’’s numeric process ID.) If the Ith character of
1 this environment variable’s value is ‘1’, do not consider the Ith
1 operand of ‘grep’ to be an option, even if it appears to be one. A
1 shell can put this variable in the environment for each command it
1 runs, specifying which operands are the results of file name
1 wildcard expansion and therefore should not be treated as options.
1 This behavior is available only with the GNU C library, and only
1 when ‘POSIXLY_CORRECT’ is not set.
1