5

I understand it is extremely rare and the concept, but can't think of a use for it. I do have an idea that we may want to execute a script that has a command to login to a server through ssh, is that something that needs to be done at times and is it an example of where a non-interactive login shell is useful?

3
  • 2
    A non-interactive logon shell is used for cron, at, batch jobs, among other tasks. "Non-interactive" means the process doesn't have a human (or expect) attached.
    – waltinator
    Dec 11, 2023 at 18:11
  • 2
    Does this answer your question? Differentiate Interactive login and non-interactive non-login shell (the title is a bit deceptive because the actual question covers all four combinations)
    – wjandrea
    Dec 12, 2023 at 1:44
  • About 5-10 years ago, LightDM would run a non-interactive login shell to start your GUI session (so it would source /etc/profile, etc. and set environment variables and such from there) - that's to say, during that time, non-interactive login shells were incredibly common, if unnoticed. Now GDM is the default and GDM doesn't do that.
    – muru
    Dec 12, 2023 at 4:47

1 Answer 1

3

Study the Unix way commands are run: the existing (login) shell is forked (duplicated), and the command is execed. If the forked shell runs another shell, that shell is non-interactive. Type in the command"

$ echo "$-  'i' indicates interactive"
himBHs  'i' indicates interactive

Now put the above line in a file (foo) and run

bash foo
hB  'i' indicates interactive

No "i", so being run in a non interactive shell. Make foo executable and try again"

chmod +x foo
./foo
hB  'i' indicates interactive

Again no "i" Unless you force things with:

bash -i foo
himBH  'i' indicates interactive

Then you again see the "i"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .