Run user-specific cleanup when an interactive login Bash exits.
Which file does Bash read?
An interactive login Bash reads ~/.bash_logout at exit when the file exists.
Detailed explanation
~/.bash_logoutCorrect. ~/.bash_logout is read when an interactive login shell exits.
Correct. ~/.bash_logout is read when an interactive login shell exits.
~/.bashrcIncorrect. ~/.bashrc is primarily an interactive non-login startup file.
Incorrect. ~/.bashrc is primarily an interactive non-login startup file.
~/.bash_profileIncorrect. ~/.bash_profile is a login-shell startup candidate.
Incorrect. ~/.bash_profile is a login-shell startup candidate.
~/.profileIncorrect. ~/.profile is a login initialization candidate, not the logout file.
Incorrect. ~/.profile is a login initialization candidate, not the logout file.
Try it yourself
An example you can run in a temporary verification environment.
man bash | col -b | grep -A3 'When a login shell exits' | sed -n '1,5p'Expected result
~/.bash_logoutを読み実行する説明Key points
- Login-shell exit
- ~/.bash_logout
- Separate from startup files
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.