S18*_*182 10 bash login bashrc
据我所知,交互shell可能登录也可能不登录,它们的启动文件是不一样的。
/etc/profile然后第一个可读的~/.bash_profile, ~/.bash_login, 和~/.profile /etc/bash.bashrc然后~/.bashrc每次使用交互式 shell 时,我都想设置一些变量,无论它是否是登录 shell。
Gil*_*il' 10
不,没有。是的,这是设计缺陷。
在 中使用以下内容~/.bash_profile:
if [ -e ~/.profile ]; then . ~/.profile; fi
if [[ -e ~/.bashrc && $- = *i* ]]; then . ~/.bashrc; fi
Run Code Online (Sandbox Code Playgroud)
请注意 bash 有一个更奇怪的怪癖:当它是非交互式登录 shell 并且父进程是rshdor 时sshd,bash 源~/.bashrc(但不是~/.bash_profileor ~/.profile)。所以你可能想把它放在你的顶部.bashrc:
if [[ $- != *i* ]]; then return; fi
Run Code Online (Sandbox Code Playgroud)
另见的.bashrc和.bash_profile文件之间的差异和登录shell和非登录shell之间的区别是什么?
| 归档时间: |
|
| 查看次数: |
3488 次 |
| 最近记录: |