I understand the basic difference between an interactive
shell and a non-interactive shell. But what exactly differentiates a
login shell from a non-login shell?
Can you give examples for uses of a non-login interactive shell?
Can you give examples for uses of a non-login interactive shell?
ANSWER:-
A login shell is the first process that executes under
your user ID when you log in for an interactive session. The login
process tells the shell to behave as a login shell with a convention:
passing argument 0, which is normally the name of the shell executable,
with a
When you log in on a text console, or through SSH, or with
It's rare to run a non-interactive login shell, but some X settings do that when you log in with a display manager, so as to arrange to read the profile files. Other settings (this depends on the distribution and on the display manager) read
When you start a shell in a terminal in an existing session (screen, X terminal, Emacs terminal buffer, a shell inside another, …), you get an interactive, non-login shell. That shell might read a shell configuration file (
When a shell runs a script or a command passed on its command line, it's a non-interactive, non-login shell. Such shells run all the time: it's very common that when a program calls another program, it really runs a tiny script in a shell to invoke that other program. Some shells read a startup file in this case (ksh and bash run the file indicated by the
† I'm simplifying a little, see the manual for the gory details.
-
character prepended (e.g. -bash
whereas it would normally be bash
. Login shells typically read a file that does things like setting environment variables: /etc/profile
and ~/.profile
for the traditional Bourne shell, ~/.bash_profile
additionally for bash†, /etc/zprofile
and ~/.zprofile
for zsh†, /etc/csh.login
and ~/.login
for csh, etc.When you log in on a text console, or through SSH, or with
su -
, you get an interactive login shell. When you log in in graphical mode (on an X display manager), you don't get a login shell, instead you get a session manager or a window manager.It's rare to run a non-interactive login shell, but some X settings do that when you log in with a display manager, so as to arrange to read the profile files. Other settings (this depends on the distribution and on the display manager) read
/etc/profile
and ~/.profile
explicitly, or don't read them.When you start a shell in a terminal in an existing session (screen, X terminal, Emacs terminal buffer, a shell inside another, …), you get an interactive, non-login shell. That shell might read a shell configuration file (
~/.bashrc
for bash, /etc/zshrc
and ~/.zshrc
for zsh, /etc/csh.cshrc
and ~/.cshrc
for csh, etc.).When a shell runs a script or a command passed on its command line, it's a non-interactive, non-login shell. Such shells run all the time: it's very common that when a program calls another program, it really runs a tiny script in a shell to invoke that other program. Some shells read a startup file in this case (ksh and bash run the file indicated by the
ENV
variable, zsh runs /etc/zshenv
and ~/.zshenv
),
but this is risky: the shell can be invoked in all sorts of contexts,
and there's hardly anything you can do that might not break something.† I'm simplifying a little, see the manual for the gory details.
0 comments:
Post a Comment
Don't Forget to comment