-bash 是什么意思?

-bash 是什么意思?

我在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


也可以看看:

相关内容