A user brian is configured to use the bash shell. His home directory is /export/home/brian, and
contains a .profile and a .bashrc file.
In the -profile, there are these lines:
genius =ritchie
export genius
In the .bashrc us this line:
genius=kernighan
In /etc/profile are these lines:
genius=thompson
export genius
When brian logs in and asks for the value of genius, what will he find, and why?
A.
genius will be ritchie, because that was the value exported in .profile.
B.
genius will be kernighan, because .bashrc executes after .profile.
C.
genius will be ritchie because variable settings in .profile take precedence over variable settings
in .bashrc.
D.
genius will be ritchie because .profile executes after .bashrc.
E.
genius will be thompson because /etc/profile system settings always override local settings.
Think this is answer A. When shell is invoke with login /etc/profile and then .profile is read last. So exported variable for genius would be ritchie.
.bashrc is read when invoked interactively as a non-login shell
Hi John,
Doesn’t matter if you export the value or not. Try excluding the export line, you will still get ritchie.
set up as above, log out, log in, echo $genius, kernighan
http://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html#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.
The answer is A because the question just asks what happens if he asks for the value after logging in. Then bash only reads up to .profile and .bashrc is not read at all. If he would use an interactive shell that is not a login shell and ask for the value then he would get kerningham since .bashrc is read. Try it by logging through ssh and by the graphical interface and asking for the value and you will see the difference.
Source: Oracle Solaris 11 System Administartion, Bill Calkins, page 471
i think the correct answer is A because here the word export is only a way of speaking