I am new to Linux and reading Advanced Linux chapter by chapter. In the Shell Scripting part, I am really confused about one question. What method does the login shell use to read /etc/profile?
What method does the login shell use to read /etc/profile?
bash;shell script;shell
It is sourced. The difference between executing and sourcing is explained in this post. The important difference here is that sourcing causes the commands in the sourced file to be run in the current shell. That means that any variables defined in the file will now be available in the shell. To illustrate the difference, try the following:$ cat foo        ## a simple file with a variable definitionvar=hello$ chmod +x foo   ## make file executable$ ./foo          ## execute$ echo $var    ## var is not set in the parent shell$ . foo          ## source$ echo $var    ## var is now set in the parent shellhelloSo, since /etc/profile needs to be able to affect the shell it was read from, it is sourced and not executed. 