Start Bash as a login shell.
The home directory contains .bash_profile, .bash_login, and .profile.
Which user file does Bash read first after /etc/profile?
A login Bash checks .bash_profile, .bash_login, and .profile in order and reads only the first existing file.
Detailed explanation
~/.bash_profileCorrect. Bash reads the first existing file, .bash_profile, and stops checking the other candidates.
Correct. Bash reads the first existing file, .bash_profile, and stops checking the other candidates.
~/.bash_loginIncorrect. Bash reaches .bash_login only when .bash_profile is absent.
Incorrect. Bash reaches .bash_login only when .bash_profile is absent.
~/.profileIncorrect. .profile is considered only when the preceding Bash-specific files are absent.
Incorrect. .profile is considered only when the preceding Bash-specific files are absent.
~/.bashrcIncorrect. .bashrc is normally for an interactive non-login shell.
Incorrect. .bashrc is normally for an interactive non-login shell.
Try it yourself
An example you can run in a temporary verification environment.
man bash | col -b | grep -A8 'When bash is invoked as an interactive login shell' | sed -n '1,10p'Expected result
.bash_profile、.bash_login、.profileをこの順に探す説明Key points
- First existing file
- .bash_profile has priority
- .bashrc is separate
Notes
- Environment: GNU Bash 5.2 / マニュアル参照
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.