When bash is invoked as an interactive login shell, which of the following sentences is true?
A.
It first reads and executes commands in /etc/bashrc and then does the same for /etc/profile.
B.
It ignores /etc/profile and only reads and executes commands in ~/.bashrc.
C.
It first reads and executes commands in /etc/profile and then does the same for ~/.bash_profile,
~/.
bash_login and ~/.profile.
D.
It first reads and executes commands in /etc/profile and then does same for ~/.bash_profile and
~/.bashrc.
E.
It reads and executes commands in ~/.bashrc only if /etc/profile or another initialisation script
calls it.
Explanation:
Startup Scripts:
For Login shell provided users:
i. /etc/profile which calls /etc/profile.d/*.sh
ii. ~./bash_profile
iii. ~/.bashrc
iv. /etc/bashrc
For non-Login Shell provided users
19
1. ~/.bashrc
2. /etc/bashrc which calls /etc/profile.d/*.sh
The answer is Option C read below.
Bash Startup Files
Invoked as an interactive login shell, or with –login
When Bash is invoked as an interactive login shell, or as a non-interactive shell with the –login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The –noprofile option may be used when the shell is started to inhibit this behavior.
When a login shell exits, Bash reads and executes commands from the file ~/.bash_logout, if it exists.
reference: http://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html
A