Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

login shell VS interactive shell

132 views
Skip to first unread message

Joao Ferreira Gmail

unread,
Oct 13, 2011, 5:50:02 PM10/13/11
to
Hello all,

I read a text about bash that mentions a difference between "login
shell" and "interactive shell".

I'm affraid I don not know the difference. Can anyone enlighten me ?


text I read was:

"When Bash starts executes the commands in a variety of different
scripts. When started as an interactive login shell: Bash reads and
executes the /etc/profile (if it exists). After reading that file, it
looks for ~/.bash_profile, ~/.bash_login, and ~/.profile in that order,
and reads and executes the first one (that exists and is readable). When
a login shell exits: Bash reads and executes ~/.bash_logout (if it
exists). When started as an interactive shell (but not a login shell):
Bash reads and executes ~/.bashrc (if it exists)."

thank you
João

--
To UNSUBSCRIBE, email to debian-us...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/1318542564.3...@wheejy.critical.pt

Raf Czlonka

unread,
Oct 13, 2011, 8:00:01 PM10/13/11
to
On Thu, Oct 13, 2011 at 10:49:24PM BST, Joao Ferreira Gmail wrote:
> Hello all,
>
> I read a text about bash that mentions a difference between "login
> shell" and "interactive shell".
>
> I'm affraid I don not know the difference. Can anyone enlighten me ?

Login shell is the shell executed at logon, the one in /etc/passwd.
Interactive shell is the one which user interacts with - it can be,
but doesn't have to, be the same as the login shell.

> text I read was:
>
> "When Bash starts executes the commands in a variety of different
> scripts. When started as an interactive login shell: Bash reads and
> executes the /etc/profile (if it exists). After reading that file, it
> looks for ~/.bash_profile, ~/.bash_login, and ~/.profile in that order,
> and reads and executes the first one (that exists and is readable). When
> a login shell exits: Bash reads and executes ~/.bash_logout (if it
> exists). When started as an interactive shell (but not a login shell):
> Bash reads and executes ~/.bashrc (if it exists)."


You can run bash, other shells as well if they support it, both as login
and interactive shell, even after you logged on.

man bash

options '-l' and '-i'

Regards,
--
Raf


--
To UNSUBSCRIBE, email to debian-us...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org

Archive: http://lists.debian.org/20111013234...@linuxstuff.pl

Bob Proulx

unread,
Oct 13, 2011, 9:20:02 PM10/13/11
to
Joao Ferreira Gmail wrote:
> I read a text about bash that mentions a difference between "login
> shell" and "interactive shell".
>
> I'm affraid I don not know the difference. Can anyone enlighten me ?
>
> text I read was:
>
> "When Bash starts executes the commands in a variety of different
> scripts. When started as an interactive login shell: Bash reads and
> executes the /etc/profile (if it exists). After reading that file, it
> looks for ~/.bash_profile, ~/.bash_login, and ~/.profile in that order,
> and reads and executes the first one (that exists and is readable). When
> a login shell exits: Bash reads and executes ~/.bash_logout (if it
> exists). When started as an interactive shell (but not a login shell):
> Bash reads and executes ~/.bashrc (if it exists)."

At login time the /bin/login program launches the shell listed in your
/etc/passwd file but it starts it in a special way so as to
communicate to it that it is the very first shell for this user. Due
to limitations at the time this is done by putting a '-' at the front
of the shell's name in the process listing. For example if you log
into a computer using ssh and look at your $0 you will find that the
shell process name starts with a dash.

mydesktop$ ssh otherhost <--- bash reads /etc/profile then
reads .bash_profile (or .profile)
otherhost$ echo $0
-bash <--- name indicates it is a login shell

Shells look at their own name and if they see that it starts with a
dash then they know that they are a login shell. As a login shell the
original Bourne shell from years ago knew it should read the user's
$HOME/.profile file. But while ksh, bash, zsh, others are similar to
Bourne shell they all expand upon it. They all read /etc/profile
since that is common to all. Then bash checks to see if there is a
.bash_profile file and if so uses that as an exact match. If not then
bash reads the standard shell .profile file which should contain only
generic commands and could be shared among many shells that all are
Bourne-shell-like.

Note that a login shell such as bash reads .bash_profile (or .profile)
but does *not* read the .bashrc file. That is why the .bashrc file is
almost always sourced explicitly from the .bash_profile (or .profile)
file. If you want it then you need to specify it. This is so that in
the special cases when it is not wanted that there is a way to avoid
it. Most of the time you want it.

That is all about login shells. But non-login interactive bash shells
read the $HOME/.bashrc file. At the command prompt if you were to
launch another shell it would simply be an interactive shell and would
only read the .bashrc file.

$ bash <--- bash reads .bashrc
$ echo $0
bash

They do not need to read the .profile again since any exported
environment variables will be inherited automatically. This is why
PATH is set in the .profile and then inherited automatically into
other shells. However aliases are not inherited. Therefore aliases
are typically placed in the .bashrc file.

Non-interactive bash shells do not source any files. However that can
be forced.

As you can see the difference between an interactive login shell and
an interactive non-login shell is simply one of organization.

Bob

signature.asc

Chris Davies

unread,
Oct 14, 2011, 4:30:02 AM10/14/11
to
Joao Ferreira Gmail <joao.miguel...@gmail.com> wrote:
> I read a text about bash that mentions a difference between "login
> shell" and "interactive shell".

> I'm affraid I don not know the difference. Can anyone enlighten me ?

I've always found bash to be singularly unhelpful with its approach to
.bash_profile and .bashrc.

Many years ago I used (t)csh and its approach seemed to be logical
and self-consistent: .cshrc is always run, *and* .login is run for
the first interactive (login) shell. This allowed me to put "run once"
configurations into .login and "every time" configurations in .cshrc.

These days I've taken this approach with bash, and I put environment
variables and other preparation into .bash_profile, and every-time
configuration into .bashrc (functions, aliases, terminal setttings,
etc.) with interactive items protected by an « if test -n "$PS1"... »
construct. The final piece of the jigsaw is a check at the top of .bashrc
to run .bash_profile - but only if it's not already been run - and a
check at the bottom of .bash_profile to chain .bashrc - again, provided
it's not already being run.

Code samples available on request (to the list).
Chris


--
To UNSUBSCRIBE, email to debian-us...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org

Archive: http://lists.debian.org/id6lm8x...@news.roaima.co.uk

Joao Ferreira Gmail

unread,
Oct 14, 2011, 5:30:01 AM10/14/11
to
On Fri, 2011-10-14 at 08:53 +0100, Chris Davies wrote:
> Joao Ferreira Gmail <joao.miguel...@gmail.com> wrote:
> > I read a text about bash that mentions a difference between "login
> > shell" and "interactive shell".
>
> > I'm affraid I don not know the difference. Can anyone enlighten me ?
>

Hello,

Thanks everybody for the explanations. I got the picture now :)

Cheers
Joao

--
To UNSUBSCRIBE, email to debian-us...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org

Archive: http://lists.debian.org/1318584235.2...@wheejy.critical.pt

0 new messages