为什么将$ 0设置为-bash?


8

第一个登录进程名称似乎设置为-bash,但是如果我使用subshel​​l,它将变为bash。例如:

root@nowere:~# echo $0
-bash
root@nowere:~# bash
root@nowere:~# echo $0
bash

-bash 导致某些脚本失败,例如 . /usr/share/debconf/confmodule

exec /usr/share/debconf/frontend -bash
Can't exec "-bash": No such file or directory at /usr/share/perl/5.14/IPC/Open3.pm line 186.
open2: exec of -bash failed at /usr/share/perl5/Debconf/ConfModule.pm line 59

有人知道为什么$0设置为-bash吗?


1
@RaduRădeanu发现猫的无用!
gniourf_gniourf 2013年

Answers:


5

如果echo $0命令的输出是,-bash则表示 bash已作为登录外壳程序调用。man bash在第126行的某处说:

A  login shell is one whose first character of argument zero is a -, or 
one started with the --login option.

在此处查看更多信息:Login Shell和Non-Login Shell之间的区别

因此您的shell仍然是静止的/bin/bash(可以通过echo $SHELL命令检查),我建议您使用该命令,该命令通常会给您带来错误:

exec /usr/share/debconf/frontend bash

谢谢,看来登录确实在登录Shell进程名称中正确添加了“-”。那回答了我的问题。
James Shimer
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.