bug-bash
[Top][All Lists]
Advanced

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

why does bash not execute .bashrc with ssh -t ?


From: Jon Seymour
Subject: why does bash not execute .bashrc with ssh -t ?
Date: Wed, 15 Oct 2008 12:11:27 +1100

I am trying to work out why .bashrc is not executing when I invoke ssh with
the -t option and _does_ execute when I invoke ssh without the -t option.

ssh -qt remote-host  which rsync  # indicates ~/.bashrc has not executed on
remote host
ssh -q remote-host   which rsync  # indicates ~/.bashrc has executed on
remote host

ssh -qt remote-host tty # reports /dev/pts/1
ssh -q remote-host tty # reports not a tty

ssh -qt remote-host echo '$-'  # reports hBc
ssh -q remote-host echo '$-'  # reports hBc

ssh -q remote-host ps -o "pid,ppid,args" -u xjsrs
  PID  PPID COMMAND
8704  8702 sshd: address@hidden
 8705  8704 ps -o pid,ppid,args -u xjsrs

ssh -qt remote-host ps -o "pid,ppid,args" -u xjsrs
  PID  PPID COMMAND
8733  8731 sshd: address@hidden/1
 8734  8733 ps -o pid,ppid,args -u xjsrs

According to echo '$-' neither shell is interactive.Yet, the one that is
started without a pseudo terminal does have .bashrc executed.

I added an debug statements to .bash_profile and it not getting executed in
either case.

There is no /etc/sshrc file and I don't have a ~/.ssh/rc file.

The bash version is:

GNU bash, version 3.00.15(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2004 Free Software Foundation, Inc.

Upon reading the manual, the rule that bash seems to be using to decide that
.bashrc should be executed if -t is not specified, is this one:

    Bash attempts to determine when it is being run by the remote shell
daemon, usually rshd.  If bash determines it is being run by rshd, it
reads  and  executes
    commands  from  ~/.bashrc,  if that file exists and is readable.  It
will not do this if invoked as sh.  The --norc option may be used to inhibit
this behavior, and
    the --rcfile option may be used to force another file to be read, but
rshd does not generally invoke the shell with those options or allow them to
be specified.

However, when I use the ssh -t option, it would seem that allocation of a
pseudo-tty is causing bash to assume that it is not being invoked by a
remote shell daemon.

Is there any way I can have an ssh pseudo-tty and get bash to execute
~/.bashrc?

jon seymour.


reply via email to

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