Are there non-interactive login shells?
I assume you're talking about Bash's concept of login vs. non-login and interactive vs. non-interactive Bash shells as described in the Invocation section of the manpage. (This is different from the interpretation in James Youngman's answer of any arbitrary command used as the "shell" (or user command interpreter) in the passwd(5)
file and whether or not that program accepts user input; some, such as /usr/sbin/nologin
, obviously don't.)
You are correct that /bin/bash --login some-script.sh
will produce a non-interactive login Bash invocation, and this is perhaps a pathological example. There is one case, perhaps uncommon but not truly weird, that produces a non-interactive login shell: ssh somehost < some-file
. Here sshd
will start Bash with argv[0]
set to -bash
because it's not been given a command to run, causing Bash to consider itself a login shell, but, because stdin is not connected to a terminal, Bash will not set itself to interactive mode ($-
will not contain i
).
(Personally, that case seems far more reasonable than the converse, ssh somehost somecommand
, which is not considered a "login shell" even though it's a fresh login to somehost
just as the above is.)
I have recently done what I should have done long ago and put together a table of Bash's modes and what init files are run. If you're finding it confusing, take heart in that at least I do as well. It mystifies me what their original aim was with the rules about when .bashrc
is executed.