gli*_*tch 4 .profile bashrc ubuntu .bash-profile tmux
在通过 SSH 连接到 Ubuntu 12.04 服务器实例时,我一直在获取我的 .profile 的来源问题。我的 .bashrc 最后执行以下操作:
if [[ "$TERM" != "screen-256color" ]]
then
tmux attach-session -t "$USER" || tmux new-session -s "$USER"
exit
fi
Run Code Online (Sandbox Code Playgroud)
如果我注释掉该代码块并再次使用 ssh 登录,则 ~/.profile 文件将按预期来源。~ 下没有 .bash_profile 或 .bash_login 这会阻止 ~/.profile 被读取。将 .profile 重命名为 .bash_profile 作为实验也没有得到文件来源。
有没有人猜测为什么会发生这种情况?我可以把所有东西都塞进 .bashrc,但我很想知道为什么 .profile 没有被采购。
正如在打开终端时为什么 ~/.bash_profile 没有获得来源中所讨论的那样?在“Ask Ubuntu”上,运行的 shelltmux不是登录 shell。
如何判断 shell 是否是“登录 shell”?
- 尝试键入“
logout”。如果 shell 终止,则它是一个登录 shell。如果它说它不是登录外壳,那么它不是。- 键入“
ps -fp$$”。(修改,如果你使用ps不同的参数,做任何你需要做的事情以获得当前 shell 的完整/长进程信息列表——“–p”的意思是“查看这个进程”,“$$”是shell。)如果进程名称以破折号(连字符)开头,如“-bash”或“-csh”,则它是登录shell;否则,它不是。(大概。)
……所以,下面运行的shelltmux不会看.bash_profile;它只会看.bashrc. 因此,将您要执行的命令从 移动.bash_profile到.bashrc,或者将它们放在两个位置,或者将一个源设为另一个。