Here it will be a little confusing, because there are both/etc/bash. bashrc has/etc/bashrc. In fact, ubuntu and debian have/etc/bash. bashrc file but no/etc/bashrc, other systems are basically only/etc/bashrc no/etc/bash. bashrc.
Final ModificationTo achieve the process we need, we must modify the rc file of the system. We will use Ubuntu as an example.
First, add/etc/profile to the file header.
export system_profile_loaded=1
In this way, other files can be determined based on $ system_profile_loaded to determine whether the profile has been loaded. Then we can see
unset ifiif [ "$PS1" ]; then if [ "$BASH" ]; then PS1='\u@\h:\w\$ ' if [ -f /etc/bash.bashrc ]; then . /etc/bash.bashrc fi else if [ "`id -u`" -eq 0 ]; then PS1='# ' else PS1='$ ' fi fifiumask 022
According to our scheme, bashrc should be loaded at the end of the file no matter what the situation is, so we modify it
unset ifiumask 022if [ "$BASH" ]; then if [ "$PS1" ]; then PS1='\u@\h:\w\$ ' fi if [ -f /etc/bash.bashrc ]; then . /etc/bash.bashrc fielse if [ "`id -u`" -eq 0 ]; then PS1='# ' else PS1='$ ' fifi
Of course, there can also be other methods, as long as it complies with the bashrc load at the end of the file.
Next, we modify/etc/bash. bashrc and add it to the file header.
[ -n "${system_bashrc_running}" ] && returnsystem_bashrc_running=1[ -z "${system_profile_loaded}" ] && source /etc/profileunset system_bashrc_runningsystem_bashrc_runned=1Among them, system_bashrc_running and other variables are added to prevent two repeated calls.
In this way, the system-level rc files are basically modified, and it is best to modify the local rc file again, so we edit "~ /. Profile ", found content is
# ~/.profile: executed by Bourne-compatible login shells.if [ -n "$BASH" ]; then if [ -f ~/.bashrc ]; then . ~/.bashrc fifimesg n
According to the above modification rules, you only need to replace
export local_profile_loaded=1if [ -n "$BASH" ]; then if [ -f ~/.bashrc ]; then . ~/.bashrc fifi
In this way, we will always load bashrc after loading the profile, and then modify it like editing/etc/bash. bashrc ~ /. Bashrc. Add it to the file header.
[ -n "${local_bashrc_running}" ] && returnlocal_bashrc_running=1[ -r /etc/bashrc -a -z "${system_bashrc_runned}" ] && source /etc/bashrc[ -r ~/.profile -a -z "${local_profile_loaded}" ] && source ~/.profileunset local_bashrc_runningIt is used to prevent repeated loading of profiles, and the special note here is
[ -r /etc/bashrc -a -z "${system_bashrc_runned}" ] && source /etc/bashrcThe/etc/bashrc file is only available in mac and other systems. Therefore, this line of ubuntu does not need to be added, but it does not matter if it has been added.
Here, the shell loading sequence cannot be solved perfectly. Of course, zsh is used by this user and needs to be modified according to the type principle.
In addition, there may be ~ /. Bash_profile ,~ Files such as/. bash_login, but bash will not load these files ~ /. Profile. If yes, delete these files and merge the files ~ /. Profile and ~ /. Bashrc.
From: http://www.linuxeye.com/Linux/bashrc-profile.html
Address: http://www.linuxprobe.com/diff-bashrcprofile.html