当我查看时man bash
,这些都没有定义。然而,网上的随机帖子提到了他们;他们来自哪里?或者他们只是一个约定?
mur*_*uru 15
它们与任何其他公约一样只是一个公约。EDITOR
并且PAGER
在标准中被提及为属于您不明智地与之冲突的变量,因为它们被广泛使用。见第 8 章第 1 节:
与广泛使用的命令解释器和应用程序经常导出的某些变量发生冲突是不明智的:
Run Code Online (Sandbox Code Playgroud)... 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.
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)
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.
Run Code Online (Sandbox Code Playgroud)
bash
手册没有提到它们并不奇怪,因为我能想到的 bash 内置函数都没有使用这些。但是,它们在其他实用程序中被广泛使用,而这三个只是我常用的。
该BROWSER
变量与EDITOR
或不在同一个联盟中PAGER
- 标准中未提及。但是,某些程序可能会使用它们,例如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 (:).
Run Code Online (Sandbox Code Playgroud)
据我所知,这是一种惯例,可以追溯到 30 多年以前。
该邮件BSD 4.2手册页的1983年4月1日提到EDITOR
,SHELL
和VISUAL
。
PAGER
在 BSD 4.2 的 "man" 版本中没有提到:
如果标准输出是电传打字机,或者如果给出了标志 -,则 man 通过 cat(1) 管道输出
但它是在大约 1990 年的 4.3 Reno 中。