Document directory
- Login shell vs non-login shell
- . Bash_profile vs. bashrc
- Which file is written?
When working in a Unix * like environment, you may encounter bash environment variable configuration. Every time you face some. Bash * files in the $ home directory, you will always temporarily forget to modify the file.
Adding configuration information to that file is normal. So why do we need to set two configuration files? What are their differences?
Find the bash help document. You can find the following description.
~ /. Bash_profile
The personal initialization file, executedLogin shells
~ /. Bashrc
The individualPer-interactive-shellStartup file
. Bash_profile is executed when you log on to the shell, while. bashrc does not open the shell in the login mode (for example, run/bin/bash ).
Login Shell vs non-Login Shell
Whether you are sitting on your computer or remotely logging on to the host through SSH,. bash_profile will be executed before the command line prompt is initialized when you log on to the terminal with your username/password.
If you have logged on to the machine and opened a new terminal (usually xterm in this way) on gnome or KDE Desktop, then. bashrc is executed before the command line prompt is initialized. Of course, as mentioned above, when you start a new bash example by executing/bin/bash on the terminal, it will also call. bashrc.
. Bash_profile vs. bashrc
For example, if you want to diagnose the terminal printer (current user, memory usage, Server Load balancer, etc.) every time you log on to the machine, you need to write the configuration information. bash_profile. If you want to prompt every time you open the terminal, it is recorded in. bashrc.
The advantage of doing so is that more precise configuration can be performed for some application scenarios.
The above description does not apply to Mac OS. For terminal. app, only. bash_profile is executed each time it is run.
Which file is written?
In most cases, you do not want to maintain the configuration file for login shell or non-login shell, because the two configuration files actually maintained are usually used for similar work. For example, if you want to set the PATH environment variable, you can run the source. bashrc command in. bash_profile and store the PATH variable setting information in. bashrc.
vim ~/.bash_profile if [ -f ~/.bashrc ]; then source ~/.bashrc fi
In this case, the. bashrc file is also executed when login arrives at the machine.
Currently, this issue has been taken into account in the new Linux version. The following code is usually added to. bash_profile:
[root@vsso ~]# cat .bash_profile # .bash_profile# Get the aliases and functionsif [ -f ~/.bashrc ]; then . ~/.bashrcfi# User specific environment and startup programsPATH=$PATH:$HOME/binexport PATHunset USERNAME
Therefore, common content can be written to the. bashrc file.