# /etc/profile: system-wide .profile file for the Bourne shell (sh(1)) # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...). if [ "PS1" ]; then if [ "BASH" ] && [ "BASH" != "/bin/sh" ]; then # The file bash.bashrc already sets the default PS1. # PS1='/h:/w/$ ' if [ -f /etc/bash.bashrc ]; then . /etc/bash.bashrc fi else if [ "`id -u`" -eq 0 ]; then PS1='# ' else PS1=' ' fi fi fi if [ -d /etc/profile.d ]; then for i in /etc/profile.d/*.sh; do if [ -r i ]; then .i fi done unset i fi 其次再打开~/.profile文件,会发现该文件中加载了~/.bashrc文件。
# if running bash if [ -n "BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "HOME/.bashrc" ]; then . "HOME/.bashrc" fi fi # set PATH so it includes user's private bin directories PATH="HOME/bin:HOME/.local/bin:PATH" 从~/.profile文件中代码不难发现,/.profile文件只在用户登录的时候读取一次,而/.bashrc会在每次运行Shell脚本的时候读取一次。