![-bash 是什么意思?](https://linux22.com/image/877720/-bash%20%E6%98%AF%E4%BB%80%E4%B9%88%E6%84%8F%E6%80%9D%EF%BC%9F.png)
我在tty1中输入命令echo $0
,它返回-bash
,为什么不呢bash
?
答案1
这表明bash
已作为登录 shell 启动。从man bash
,部分INVOCATION
(重点是我的):
A login shell is one whose first character of argument zero is a -, or
one started with the --login option.
...
When bash is invoked as an interactive login shell, or as a non-inter‐
active shell with the --login option, it first reads and executes com‐
mands 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 a login shell exits, bash reads and executes commands from the
file ~/.bash_logout, if it exists.
$0
当然是零论点。
在 Ubuntu 中,通常.profile
存在并且.bash_profile
不.bash_login
存在。因此,登录 shell 读取.profile
。
也可以看看: