In interpreting this flowchart
I found that in man bash:
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.
That states that interactive login shells read
/etc/profile (without --noprofile)
Also, non-interactive shells with the option
That seems to leave some possible login shells (in which the
$0 starts with a
-) that being non-interactive (run an script, maybe as simple as
date) may not read (source)
To confirm or deny this idea:
First I tried to use
su -l -, which starts a login shell with a
- as the first character but I fail to make it non-interactive (and be able to present the tests to probe it).
Calling something like
$ bash -c 'date' -bash
Doesn't report to be an login shell (even if the first character is a
Try this to reveal the detail:
$ bash -c 'echo "$0 $- ||$(shopt -p login_shell)||";date' -bash -bash hBc ||shopt -u login_shell|| Fri Aug 19 06:32:31 EDT 2016
-as the first character, there is no
i(interactive) in the value of
$-but it is not reported as a
login_shell(the -u). In this case, /etc/profile was not read, but I am not sure this is the right test.
There is also the mention of "rare non-interactive login shells" in this answer without being specific enough for this question.
The conclusion of this guy is that
/etc/profile is always read.
Read the summary table: both interactive and non-interactive login shells read
And, if the examples from this page are correct:
Some examples $ su bob # interactive non-login shell $ su - bob # interactive login shell $ exec su - bob # interactive login shell $ exec su - bob -c 'env' # non-interactive login shell $ ssh firstname.lastname@example.org # interactive login shell, `~/.profile` $ ssh email@example.com env # non-interactive non-login shell, `~/.bashrc`
The test of
exec su - bob -c 'env' reports that
/etc/profile was read.
Is it possible to have a non-interactive login shell (not called with --login or -l)?
And if true, is it reading the
If the above is true we have to conclude that ALL login shells [interactive (or not)] read /etc/profile (with no
Note: to detect that /etc/profile is being read, just add at the very beginning of the file this command:
echo "'/etc/profile' is being read"