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: Linda Walsh
Subject: Re: .bashrc is sourced even for non-interactive shells (when run from sshd)
Date: Sat, 02 Jun 2012 17:05:35 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.24) Gecko/20100228 Lightning/0.9 Thunderbird/2.0.0.24 Mnenhy/0.7.6.666



Pierre Gaston wrote:

On Sat, Jun 2, 2012 at 8:24 PM, Mikel Ward <mikel@mikelward.com> wrote:
On Sat, Jun 2, 2012 at 10:19 AM, Pierre Gaston <pierre.gaston@gmail.com> wrote:
On Sat, Jun 2, 2012 at 8:15 PM, Mikel Ward <mikel@mikelward.com> wrote:
bash sources .bashrc even for some non-interactive shells.
...
"Remote non login non interactive shells"
Bash has a special compile time option that will cause it to source
the .bashrc file on non-login, non-interactive ssh sessions.
IIUC, it was once a compile time option, but it's now hard-coded. �The
isnetconn test doesn't seem to be toggled by any macro.

� � �if ((run_by_ssh || isnetconn (fileno (stdin))) && shell_level < 2)
but  run_by_ssh is:

#ifdef SSH_SOURCE_BASHRC
      run_by_ssh = (find_variable ("SSH_CLIENT") != (SHELL_VAR *)0) ||
                   (find_variable ("SSH2_CLIENT") != (SHELL_VAR *)0);
#else
      run_by_ssh = 0;
#endif



I would say that's broken -- bash can detect if it is
hooked up to a terminal for input, or not, but chooses not to.

prelude:

ans=("is "{not,}" a tty")
alias sub=function
sub echoAns { echo ${ans[$?==0]}; }
alias }{=else {=then }=fi ?=if

4 basic cases...

1)
Ishtar:...> if ssh  ishtar isatty 0 2>/dev/null; { echoAns; }{ echoAns; }
.bashrc STDIN: is not a tty ( $-=hBc )
is not a tty


2)
Ishtar:...> if ssh -T ishtar isatty 0 2>/dev/null; { echoAns; }{ echoAns; }
.bashrc STDIN: is not a tty ( $-=hBc )
is not a tty


3)
Ishtar:...> if ssh -tn ishtar isatty 0 2>/dev/null; { echoAns; }{ echoAns; }
.bashrc STDIN: is not a tty ( $-=hBc )
is not a tty


4)
Ishtar:...> if ssh -t ishtar isatty 0 2>/dev/null; { echoAns; }{ echoAns; }
.bashrc STDIN: is a tty ( $-=hBc )
is a tty

While it is arguable whether or not 1 & 2 are 'interactive' (they are but not in a character oriented way), #4, by:
       --rcfile file
              Execute commands from file instead of the standard personal ini-
              tialization file ~/.bashrc if  the  shell  is  interactive  (see
              INVOCATION below).
-----------Under invocation:
       An interactive shell is one started without  non-option  arguments  and
       without the -c option whose standard input and error are both connected
       to terminals .....

  ***(as determined by isatty(3)),***

       or one started with  the  -i
       option.   PS1 is set and $- includes i if bash is interactive, allowing
       a shell script or a startup file to test this state.


By using the isatty test, none of 1-3 should be calling bashrc.
You can note that the "-i" switch isn't specified at any point.

Minimally I would claim #4 to be a bug, and from the manual, #1 and #2 are as
well. (-n redirects STDIN from /dev/null -- a definite "non-winner for interactivity).









reply via email to

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