{"title": "bash\u914d\u7f6e\u6587\u4ef6\u3001login shell\u548c\u975elogin shell", "update_time": "2014-02-11 23:14:21", "tags": "shell bash", "pid": "278", "icon": "linux.png"}
## 影响到bash环境变量的文件 下面这些文件都会对Bash的环境变量有影响 ``` /etc/bashrc /etc/profile ~/.bashrc ~/.bash_profile ``` ## bash之login shell、非login shell |bash进程产生的场景 | login shell | 非login shell | |-----------------|----------------|---------------| |ssh登录 | **Y** | N | |su - 切换到用户 | **Y**| N | |tmux新建窗口 | **Y** | N | |screen新建窗口 | N | **Y** | |ssh 远程执行 /bin/bash 脚本 | N | **Y** \ ## bash配置文件的生效场景 |shell类型 | /etc/profile 和 ~/.bash_profile | /etc/bashrc 和 ~/.bashrc | |----------|-----------------------------------|---------------------------| |login shell | 有效 | **有效**(~/.bash_profile一般会source ~/.bashrc) | |非login shell | 无效 | 有效 | ## bash初始化配置应该写在哪里 对于Redhat和CentOS系列的系统,/etc/bashrc和~/.bashrc在login shell 和非login shell的情景下都会被执行到。 如果想要环境变量在login shell和非login shell的场景下都被执行到,最佳的配置写入位置是~/.bashrc