bash的环境配置文件

本文发布时间: 2019-Mar-22
1. login shell 和 non-login shelllogin shell 和 non-login shell 区别在于登录 login。login shell : 通过完整的登录流程, 举例:通过tty1-tty6 登录,需要输入用户的账号和密码,此时取得的 bash 就是 login shell。non-login shell : 取得bash接口的方法不需要重复登陆,比如下面两种方法: 1, 以 X Window登录linux后, 再以 X 的图形界面启动终端机,此时这个终端没有再次输入用户名和密码,这个bash环境为 non-login shell 2, 在原bash下再次执行bash,同样没有输入用户名和密码,此时第二个bash,子进程,为non-login shell。login shell 与 non-login shell 读取的配置文件不一样。2. login shell login shell 读取两个配置文件:1. /etc/profile2. ~/.bash_profile,或 ~/.bash_login, 或 ~/.profile。2.1 /etc/profile这个配置为用户整体的配置,最好不要修改这个文件,除非给所有用户设置整体环境。这个文件设置的变量主要有:PATH : 跟据用户设置USER: 用户名HOSTNAME: 主机名HISTSIZE : 历史命令条数该文件会调用下面文件:/etc/inputrc : 主要设置bash 热键,[Tab] 有没有声音等。/etc/profile.d/*.sh : 主要规定bash接口的颜色,语系等,如果要给所有用户设置配置变量时,在/etc/profile.d/目录下,建 .sh 文件。/etc/sysconfig/i18n: 该文件由/etc/profile.d/lang.sh 文件调用, 设置bash默认使用哪种语系。2.2 ~/.bash_profilebash读取完整体环境变量/etc/profile 后会读取个人用户配置。主要有下面三个文件:1. ~/.bash_profile2. ~/.bash_login3. ~/.profile只会读取其中一个文件,顺序为上面的顺序,只要前面文件存在,后面则不再读取。$ vim ~/.bash_profile # .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then . ~/.bashrcfi# User specific environment and startup programsPATH=$PATH:$HOME/binexport PATHunset USERNAME该文件会读取 ~/.bashrc 文件。source和. 为读入配置文件。]$ source .bashrc ]$ . .bashrc 3. non-login shellnon-login shell 会读取 ~/.bashrc查看该文件:# .bashrc# User specific aliases and functions# Source global definitionsif [ -f /etc/bashrc ]; then . /etc/bashrcfialias rm='rm -i'会读取 /etc/bashrc该文件会设置:跟据UID设置umaskPS1: 提示符调用/etc/profile.d/*.sh4. 其他配置/etc/man.config 配置手册的目录,man 命令~/.bash_history 记录bash的历史命令~/.bash_logout 注销bash时,希望系统做的一些处理。地址:http://blog.csdn.net/yonggang7/article/details/40953363


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:10pm
栏目列表