About Bash Profile And Bash.Rc On Mac OS
The macOS Terminal.app uses a series of scripts and configuration files to set up the shell environment before you see the command prompt. Here’s an overview of these files and how they are executed:
-
/etc/profile: This is a system-wide configuration file that is executed for all users when they start a new shell session. It sets up environment variables and configurations that are applicable to all users.
-
/etc/bashrc: This file is also system-wide and is typically sourced (executed) by
/etc/profile. It can contain additional configurations and environment variables that apply to all users and all shell sessions. -
/etc/bashrc_Apple_Terminal: This is a macOS-specific extension of the
/etc/bashrcfile. It contains configurations that are specifically intended for Terminal.app. -
~/.bash_profile: This is a user-specific configuration file that is executed when a user logs in. If this file exists, it takes precedence over other configuration files. Users can use this file to set up their own custom environment variables and configurations.
-
~/.bash_login: If
~/.bash_profiledoes not exist, the shell looks for~/.bash_loginand executes it if it’s present. This file is another option for users to customize their shell environment. -
~/.profile: If neither
~/.bash_profilenor~/.bash_loginexists, the shell will use~/.profilefor user-specific configurations. -
~/.bashrc: Users can optionally choose to source (execute)
~/.bashrcfrom their~/.bash_profile. This allows them to keep common configurations in~/.bashrcand have them applied to both login and non-login shell sessions.