bug-bash
[Top][All Lists]
Advanced

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

Re: .bashrc is sourced even for non-interactive shells (when run from ss


From: Pierre Gaston
Subject: Re: .bashrc is sourced even for non-interactive shells (when run from sshd)
Date: Sun, 3 Jun 2012 11:25:56 +0300

On Sun, Jun 3, 2012 at 11:02 AM, Linda Walsh <bash@tlinx.org> wrote:
>
>
> Pierre Gaston wrote:
>>
>> In all your examples the shell will be called like: bash -c  'isatty 0
>> 2'. If you use a bash compiled with the above option you can add 'ps
>> -p$$ -ocmd' at the top of your .bashrc to verify it.
>>
>> They are all non-interactive because they are called with -c,
>> disregarding if they are connected to a terminal or not.
>
> ===
> I see what you mean...
>
> Wouldn't that '*doubly*' mean the .bashrc shouldn't be called?
>

That's precisely the subject of this thread.

I thought I was not documented (before 4 it was a bit less obvious
to find the relevant bit) that's why I gave the link, but it is in
fact documented.
Eg in the bash 4 manual:

        Bash attempts  to determine  when it is  being run  with its
        standard input  connected to  a network connection,  as when
        executed by  the remote shell  daemon, usually rshd,  or the
        secure shell  daemon sshd.  If  bash determines it  is being
        run  in this fashion,  it reads  and executes  commands from
        ~/.bashrc  and  ~/.bashrc,  if  these files  exist  and  are
        readable.

If I'm not mistaken this feature is inherited from csh. I can
guess some people are using it since there is this workaround
testing for the SSH variables to make it work with openssh>5.

You can see some people having troubles with that because .bashrc
is also sourced if you use less obvious non-interactive shells,
like when you use "scp"

That's why you can find things like:

[ -z "$PS1" ] && return

in the default .bashrc of debian.



reply via email to

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