Are the concepts of login/non-login shells the same as the concepts of non-interactive/interactive shells (respectively)?
Or are the concepts orthogonal yielding four different combinations?
I am trying to get a clear picture of which .bashrc, .bash_profile scripts get sourced under various circumstances and I find that articles sometimes use these concepts interchangeably.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
-
login shell: A login shell logs you into the system as a specific user, necessary for this is a username and password. When you hit ctrl+alt+F1 to login into a virtual terminal you get after successful login: a login shell (that is interactive). Sourced files:
/etc/profileand~/.profilefor Bourne compatible shells (and/etc/profile.d/*)~/.bash_profilefor bash/etc/zprofileand~/.zprofilefor zsh/etc/csh.loginand~/.loginfor csh
-
non-login shell: A shell that is executed without logging in, necessary for this is a current logged in user. When you open a graphic terminal in gnome it is a non-login (interactive) shell. Sourced files:
/etc/bashrcand~/.bashrcfor bash
-
interactive shell: A shell (login or non-login) where you can interactively type or interrupt commands. For example a gnome terminal (non-login) or a virtual terminal (login). In an interactive shell the prompt variable must be set (
$PS1). Sourced files:/etc/profileand~/.profile/etc/bashrcor/etc/bash.bashrcfor bash
-
non-interactive shell: A (sub)shell that is probably run from an automated process you will see neither input nor output when the calling process don’t handle it. That shell is normally a non-login shell, because the calling user has logged in already. A shell running a script is always a non-interactive shell, but the script can emulate an interactive shell by prompting the user to input values. Sourced files:
/etc/bashrcor/etc/bash.bashrcfor bash (but, mostly you see this at the beginning of the script:[ -z "$PS1" ] && return. That means don’t do anything if it’s a non-interactive shell).- depending on shell; some of them read the file in the
$ENVvariable.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0