Pierre Gaston wrote:
On Sat, Jun 2, 2012 at 8:24 PM, Mikel Ward <mi...@mikelward.com> wrote:
On Sat, Jun 2, 2012 at 10:19 AM, Pierre Gaston <pierre.gas...@gmail.com> wrote:
On Sat, Jun 2, 2012 at 8:15 PM, Mikel Ward <mi...@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).