EDITOR、PAGER、BROWSER 环境变量从哪里来?

EDITOR、PAGER、BROWSER 环境变量从哪里来?

当我查看时,man bash这些都没有定义。然而,网上随机的帖子提到了它们;他们来自哪里?或者它们只是一个约定?

答案1

它们只是一个约定,就像任何其他约定一样。EDITORPAGER在标准中被提到属于属于您不明智的冲突变量,因为它们被广泛使用。看第 8 章第 1 节:

与广泛使用的命令解释器和应用程序经常导出的某些变量发生冲突是不明智的:

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

各种程序尊重它们的各种组合:

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.

手册没有提到它们并不奇怪bash,因为我能想到的 bash 内置函数都没有使用其中的任何一个。然而,它们广泛用于其他实用程序,这三个只是常用。


该变量与或BROWSER不在同一级别- 标准中未提及该变量。但是,某些程序可能会使用它们,例如:EDITORPAGERman

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 (:).

答案2

从我记事起,这个惯例就已经有 30 多年的历史了。

BSD 4.2 邮件手册页1983 年 4 月 1 日提到EDITOR、、SHELLVISUAL

PAGERBSD 4.2 版本的“man”中没有提到:

如果标准输出是电传打字机,或者如果给出了标志 - ,则 man 通过 cat(1) 传输其输出

但它出现在 1990 年左右的 4.3 Reno 中。

相关内容