A user starts a new terminal window in a running graphical desktop session, which launches bash as an interactive shell that is NOT a login shell. Which file in the user's home directory does bash read in that case?
LPIC-1 Exam 101-500, objective 103. GNU and Unix commands medium
Draft — not checked yet. This question was written from the published exam objectives and cites the clause it comes from, but nobody has yet read it against that clause and signed for it.
It is kept out of search results and out of mock exams until they have. Read the source below before you take the answer as settled.
The options
Correct ~/.bashrc
Correct. An interactive non-login bash reads ~/.bashrc. That is why aliases and prompt settings belong there rather than in the login files.
Not correct ~/.bash_profile
Wrong. ~/.bash_profile is read by interactive LOGIN shells (console login, ssh, su -). Many distributions have it source ~/.bashrc so the settings appear in both, but bash itself does not read it for a non-login shell.
Not correct ~/.bash_logout
Wrong. ~/.bash_logout is executed when a login shell exits, not when a shell starts.
Not correct ~/.profile
Wrong. ~/.profile is a login-shell file, read by bash only when ~/.bash_profile and ~/.bash_login are absent.
Why
Bash uses two different startup paths. Interactive login shells read /etc/profile and then the first of ~/.bash_profile, ~/.bash_login, ~/.profile. Interactive non-login shells read ~/.bashrc (and usually /etc/bash.bashrc or /etc/bashrc, depending on the distribution). A terminal opened inside an existing desktop session is the classic non-login case, so ~/.bashrc is the file that runs.
Where this comes from
- Cited
- LPI exam objective 103.1
- What it says
- Shell startup: which bash configuration files apply to login and non-login shells.
Practise this
Reading one question is not practice. The trainer will draw a set from objective 103 and space the ones you get wrong.