配置文件
有关 shell 配置文件
/etc/profile 此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从 /etc/profile.d 目录的配置文件中搜集 shell 的设置。 /etc/bashrc 为每一个运行 bash shell 的用户执行此文件.当 bash shell 被打开时,该文件被读取。 ~/.bash_profile 每个用户都可使用该文件输入专用于自己使用的 shell 信息,当用户登录时,该文件仅仅执行一次! 默认情况下,他设置一些环境变量,执行用户的 .bashrc 文件。 ~/.bashrc 该文件包含专用于你的 bash shell 的 bash 信息,当登录时以及每次打开新的 shell 时,该该文件被读取。 ~/.bash_logout 少见,但是意味着当每次退出系统(退出 bash shell)时,执行该文件。
另外 /etc/profile 中设定的变量(全局)的可以作用于任何用户, 而 ~/.bashrc 等中设定的变量(局部)只能继承 /etc/profile 中的变量,他们是"父子"关系。
profile 用于登录式 shell, 而 bashrc 用于每个交互式 shell ~/.bash_profile 是交互式、login 方式进入 bash 运行的 ~/.bashrc 是交互式 non-login 方式进入 bash 运行的 通常二者设置大致相同,所以通常前者会调用后者。 所以一般优先把变量设置在 .bashrc 里面。比如在 crontab 里面执行一个命令,.bashrc 设置的环境变量会生效,而 .bash_profile 不会。
设置生效:可以重启生效,也可以使用命令:source
bash 的一些参数
--noprofile
Do not read either the system-wide startup file /etc/profile or any of the personal initialization
files** ~/.bash_profile, ~/.bash_login, or ~/.profile**. By default, bash reads these files when it is in‐
voked as a login shell (see INVOCATION below).
--norc Do not read and execute the system wide initialization file /etc/bash.bashrc and the personal initial‐
ization file **~/.bashrc** if the shell is interactive. This option is on by default if the shell is in‐
voked as sh.
When an interactive shell that is not a login shell is started, bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist. This may be inhibited by using the --norc option. The ** --rcfile file option will force **bash to read and execute commands from file instead of /etc/bash.bashrc and ~/.bashrc.