[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] The execution of /etc/bash.bashrc and ~/.bashrc for non

From: Cristian Zoicas
Subject: Re: [Help-bash] The execution of /etc/bash.bashrc and ~/.bashrc for non interactive shells
Date: Thu, 6 Apr 2017 09:30:59 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:43.0) Gecko/20100101 Firefox/43.0 SeaMonkey/2.40

Thank  you  Chet  for  shedding  some   light  on  this  matter.   Now  it  is
understandable that  due to a  request that dates back  to the late  1990s was
decided  that bash  has to  execute  .basrc when  it is  started remotely  and
non-interactively, but I  still have the feeling that I  am missing something.
Please let me explain may doubts.

1) When logging into a virtual console bash executes the system/user profiles 
(/etc/profile and ~/.profile)
2) When running "su - <username>" bash  executes the system/user profiles 
(/etc/profile and ~/.profile)
3) When running "su - <username> -c ls -l" bash  executes the system/user 
profile (/etc/profile and ~/.profile)
4) When running "bash" at the command prompt bash  executes .bashrc (and 
eventually bash.bashrc)
5) When running "bash -c 'echo "Hello World!"' " bash DOES NOT execute .bashrc 
(and eventually bash.bashrc)

In all these cases above bash behaves  very well and in my opinion as expected
by most users.

Now let's analize what happens under ssh.

 I) When running "ssh address@hidden" bash executes the system/user profiles 
(/etc/profile and ~/.profile)
II) When running "ssh address@hidden ls -l" the system/user profiles are not 
executed but .bashrc is executed.

In case I) when  the user logs on the system/user  profiles are executed. This
is consistent with all the behavior presented so far.

But in the second case the things are very surprising:

    a) although the user is authenticated the system/user profiles are not
       executed, and

    b) to  make the  things even  more confusing, although  the shell  is not
       interactive .bashrc is executed.

All this behavior is documented in the man pages of ssh and bash, but I simply
cannot  understand  why  was  not  possibile   to  start  a  login  shell  and
consequently to have bash loading the system/user profiles instead of starting
a non-interactive shell that loads .bashrc.  This is also in contrast with the
purpose of  the .bashrc files that  must prepare the shell  for an interactive
session (which does not occur in the case II).

Why the request of loading .bashrc and the impossibility of starting a login 
shell (when a login is performed)?


reply via email to

[Prev in Thread] Current Thread [Next in Thread]