Environment Variables – Origin of EDITOR, PAGER, BROWSER Variables

environment-variables

When I look in man bash none of these are defined. However, random posts online refer to them; where do they come from? Or are they just a convention?

Best Answer

They are just a convention as much as any other convention. EDITOR and PAGER are mentioned in the standards as belonging to variables you'd be unwise to conflict with since they are widely used. See Chapter 8, Section 1:

It is unwise to conflict with certain variables that are frequently exported by widely used command interpreters and applications:

...
EDITOR
...
PAGER
...
VISUAL
...

Various programs respect various combinations of them:

man 1 crontab (POSIX):

   The  following  environment  variables  shall  affect  the execution of
   crontab:

   EDITOR Determine the editor  to  be  invoked  when  the  -e  option  is
          specified.  The default editor shall be vi.

man 8 sudoedit:

 2.   The editor specified by the policy is run to edit the
      temporary files.  The sudoers policy uses the
      SUDO_EDITOR, VISUAL and EDITOR environment variables (in
      that order).  If none of SUDO_EDITOR, VISUAL or EDITOR
      are set, the first program listed in the editor
      sudoers(5) option is used.

man 1 man (POSIX):

ENVIRONMENT VARIABLES
   The following environment variables shall affect the execution of man:
...
   PAGER  Determine  an output filtering command for writing the output to
          a terminal. Any string acceptable as a command_string operand to
          the  sh  -c  command  shall  be valid. When standard output is a
          terminal device,  the  reference  page  output  shall  be  piped
          through  the command.  If the PAGER variable is null or not set,
          the command shall be either more or  another  paginator  utility
          documented in the system documentation.

It is not surprising that the bash manual doesn't mention them, as none of the bash builtins that I can think of make use of any of these. However, they are widely used in other utilities, and these three are just the ones that I commonly use.


The BROWSER variable is not in the same league as EDITOR or PAGER - it is not mentioned by the standards. However, some programs may use them, like man:

man 1 man (Debian):

BROWSER
      If $BROWSER is set, its value is a colon-delimited list of  com-
      mands,  each  of  which  in  turn  is used to try to start a web
      browser for man --html.  In each command, %s is  replaced  by  a
      filename  containing  the HTML output from groff, %% is replaced
      by a single percent sign (%), and %c is replaced by a colon (:).
Related Question