每当我打开 bash 终端时,都会返回错误代码 1:
Last login: Tue Jan 15 16:19:53 on ttys000
spam@moss:~ $ echo $?
1
Run Code Online (Sandbox Code Playgroud)
我发现这是由我的最后一行代码引起的.bash_profile:
test -f $HOME/.debug && export profile_bash_profile='.bash_profile' || return 0
Run Code Online (Sandbox Code Playgroud)
如果删除此行,则返回错误代码 0。我不明白这一行是如何引起任何问题的,因为我可以.bash_profile使用错误代码 0:
spam@moss:~ $ source .bash_profile
spam@moss:~ $ echo $?
0
Run Code Online (Sandbox Code Playgroud)
更新:
有谁知道 Mac 是如何加载 ~/.bash_profile 的?当登录外壳启动时,我怀疑 Mac 的来源。该return命令似乎没有按预期运行 - 当我将其return 5作为最后一行~/.bash_profile并启动登录 shell 时,它不会返回错误代码 5(我确定~/.bash_profile是加载的最后一个脚本)。