配置oh-my-bash
2022年12月18日大约 7 分钟
上一级页面:index-la
前言
操作手册
首先查看bash的操作手册
man bash.1
The following paragraphs describe how bash executes its startup files. If any of the files
exist but cannot be read, bash reports an error. Tildes are expanded in filenames as de‐
scribed below under Tilde Expansion in the EXPANSION section.
When bash is invoked as an interactive login shell, or as a non-interactive shell with the
--login option, it first reads and executes commands from the file /etc/profile, if that file
exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile,
in that order, and reads and executes commands from the first one that exists and is readable.
The --noprofile option may be used when the shell is started to inhibit this behavior.
When an interactive login shell exits, or a non-interactive login shell executes the exit
builtin command, bash reads and executes commands from the file ~/.bash_logout, if it exists.
When an interactive shell that is not a login shell is started, bash reads and executes com‐
mands from /etc/bash.bashrc and ~/.bashrc, if these files exist. This may be inhibited by us‐
ing the --norc option. The --rcfile file option will force bash to read and execute commands
from file instead of /etc/bash.bashrc and ~/.bashrc.
When an interactive shell that is not a login shell is started, bash reads and executes com‐
mands from /etc/bash.bashrc and ~/.bashrc, if these files exist. This may be inhibited by us‐
ing the --norc option. The --rcfile file option will force bash to read and execute commands
from file instead of /etc/bash.bashrc and ~/.bashrc.
When bash is started non-interactively, to run a shell script, for example, it looks for the
variable BASH_ENV in the environment, expands its value if it appears there, and uses the ex‐
panded value as the name of a file to read and execute. Bash behaves as if the following com‐
mand were executed:
if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
but the value of the PATH variable is not used to search for the filename.
If bash is invoked with the name sh, it tries to mimic the startup behavior of historical ver‐
sions of sh as closely as possible, while conforming to the POSIX standard as well. When in‐
voked as an interactive login shell, or a non-interactive shell with the --login option, it
first attempts to read and execute commands from /etc/profile and ~/.profile, in that order.
The --noprofile option may be used to inhibit this behavior. When invoked as an interactive
shell with the name sh, bash looks for the variable ENV, expands its value if it is defined,
and uses the expanded value as the name of a file to read and execute. Since a shell invoked
as sh does not attempt to read and execute commands from any other startup files, the --rcfile
option has no effect. A non-interactive shell invoked with the name sh does not attempt to
read any other startup files. When invoked as sh, bash enters posix mode after the startup
files are read.
When bash is started in posix mode, as with the --posix command line option, it follows the
POSIX standard for startup files. In this mode, interactive shells expand the ENV variable
and commands are read and executed from the file whose name is the expanded value. No other
startup files are read.
Bash attempts to determine when it is being run with its standard input connected to a network
connection, as when executed by the remote shell daemon, usually rshd, or the secure shell
daemon sshd. If bash determines it is being run in this fashion, it reads and executes com‐
mands from ~/.bashrc and ~/.bashrc, if these files exist and are readable. It will not do
this if invoked as sh. The --norc option may be used to inhibit this behavior, and the --rc‐
file option may be used to force another file to be read, but neither rshd nor sshd generally
invoke the shell with those options or allow them to be specified.
If the shell is started with the effective user (group) id not equal to the real user (group)
id, and the -p option is not supplied, no startup files are read, shell functions are not in‐
herited from the environment, the SHELLOPTS, BASHOPTS, CDPATH, and GLOBIGNORE variables, if
they appear in the environment, are ignored, and the effective user id is set to the real user
id. If the -p option is supplied at invocation, the startup behavior is the same, but the ef‐
fective user id is not reset.
放一段机翻出来
下面几段描述了bash如何执行其启动文件。 如果任何文件
存在但不能被读取,bash会报告一个错误。 字母在文件名中的扩展方式是
在下面EXPANSION部分的Tilde扩展中描述的。
当bash作为一个交互式登录shell被调用时,或者作为一个非交互式shell使用
--login选项,它首先读取并执行文件/etc/profile中的命令,如果该文件存在的话。
存在的话。 读取该文件后,它会依次寻找~/.bash_profile、~/.bash_login和~/.profile。
的顺序,并从第一个存在且可读的文件中读取和执行命令。
在启动shell时可以使用--noprofile选项来抑制这种行为。
当一个交互式登录shell退出时,或者一个非交互式登录shell执行exit
内置命令时,bash会读取并执行文件~/.bash_logout中的命令,如果它存在的话。
当一个非登录外壳的交互式外壳启动时,bash会从/etc/bash_logout文件中读取并执行命令。
bash从/etc/bash.bashrc和~/.bashrc读取并执行命令,如果这些文件存在的话。 这可以通过使用
摄取--norc选项。 --rcfile文件选项将强制bash从文件中读取和执行命令
而不是从/etc/bash.bashrc和~/.bashrc。
当一个非登录shell的交互式shell启动时,bash会从/etc/bash.bashrc和~/.bashrc中读取并执行命令。
bash从/etc/bash.bashrc和~/.bashrc中读取并执行命令,如果这些文件存在的话。 这可以通过使用
摄取--norc选项。 --rcfile文件选项将强制bash从文件中读取和执行命令
而不是从/etc/bash.bashrc和~/.bashrc。
当bash以非交互式方式启动时,例如,为了运行一个shell脚本,它会寻找
变量BASH_ENV,如果它出现在环境中,就扩展其值,并使用扩展后的值作为
扩充后的值作为要读取和执行的文件的名称。 Bash的行为就像下面的com-
命令被执行。
if [ -n "$BASH_ENV" ]; then . "$BASH_ENV"; fi
但是PATH变量的值不会被用来搜索文件名。
如果bash以sh的名字被调用,它就会尽量模仿sh的历史版本的启动行为。
sions的启动行为,同时也符合POSIX标准。 当在
当作为一个交互式的登录shell,或者一个带有--login选项的非交互式shell被调用时,它
首先尝试从/etc/profile和~/.profile中读取和执行命令,依次进行。
可以使用--noprofile选项来抑制这种行为。 当作为一个交互式
shell的时候,bash会查找变量ENV,如果定义了它,就扩展其值。
并使用扩展后的值作为要读取和执行的文件的名称。 由于一个以sh调用的shell
不会试图从任何其他启动文件中读取和执行命令,所以 --rcfile
选项没有作用。 一个以sh名字调用的非交互式shell并不试图
读取任何其他启动文件。 当以sh调用时,bash在读取启动文件后进入posix模式。
文件后进入posix模式。
当bash以posix模式启动时,如使用--posix命令行选项,它遵循
POSIX标准来处理启动文件。 在这种模式下,交互式shells会扩展ENV变量
并从名称为扩展值的文件中读取和执行命令。 没有其他
读取其他启动文件。
Bash试图确定它是在标准输入连接到网络的情况下运行的。
连接时,如由远程shell守护进程(通常是rshd)或安全shell
守护程序sshd。 如果bash确定它是以这种方式运行的,它就会读取并执行~/.bashr中的代码。
和~/.bashrc中的命令,如果这些文件存在并且可读的话。 如果以sh的形式调用,它将不做
如果以sh方式调用,它不会这样做。 可以使用--norc选项来抑制这种行为,而--rc-
选项可以用来强制读取另一个文件,但是rshd和sshd一般都不会
用这些选项来调用shell,或者允许指定这些选项。
如果shell启动时的有效用户(组)ID不等于实际用户(组)ID
id启动,并且没有提供-p选项,则不会读取启动文件,shell函数也不会从环境中获取。
从环境中继承,SHELLOPTS、BASHOPTS、CDPATH和GLOBIGNORE等变量,如果它们出现在环境中,将被忽略。
如果它们出现在环境中,则被忽略,有效用户ID被设置为真实用户ID。
id。 如果在调用时提供了-p选项,启动行为是相同的,但有效用户ID不会被重置。
有效用户ID不被重置。
通过www.DeepL.com/Translator(免费版)翻译