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 --login read /etc/profile
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) /etc/profile.
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 2016The
$0has a-as the first character, there is noi(interactive) in the value of$-but it is not reported as alogin_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 /etc/profile
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 bob@example.com # interactive login shell, `~/.profile`
$ ssh bob@example.com env # non-interactive non-login shell, `~/.bashrc`
The test of exec su - bob -c 'env' reports that /etc/profile was read.
In short:
Is it possible to have a non-interactive login shell (not called with --login or -l)?
And if true, is it reading the /etc/profile file?
If the above is true we have to conclude that ALL login shells [interactive (or not)] read /etc/profile (with no --noprofile option).
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"

--loginoption. For the second one, if I doexec -a "-bash" "bash" <<<"shopt -p login_shell; echo $0 $-"I get (encoded in C qoutes)$'/etc/profile read\nshopt -s login_shell\nbash himBH'so, it is login but it is interactive. We need login and non-interactive. What is it that I am missing? – Aug 19 '16 at 14:16<<<"$-", that$-is expanded by the calling shell because of the double quotes. The called shell is not interactive because its stdin is not a tty. – Stéphane Chazelas Aug 19 '16 at 14:18exec -a "-bash" "bash" <<\EOF shopt -p login_shell; echo $0 $- EOFto get this confirmation:$'/etc/profile read stdin: is not a tty shopt -s login_shell -bash hB'So, yes, a non-interactive login shell is possible, and it still read/etc/profile. Should we conclude that ALL login shells read/etc/profile? – Aug 19 '16 at 14:33exec -a "-ksh" "ksh" <<\EOF echo $0; set -o EOF, :). – Aug 19 '16 at 14:47bash, the start-up file handling is pretty messed-up IMO, you'll find that some systems have patched it to have a more reasonable behaviour adding even more variation. – Stéphane Chazelas Aug 19 '16 at 14:47