An inexplicable omission in bash's sourcing of .bashrc

May 3, 2009

I discovered recently that I missed a case in my writeup of when bash sources your .bashrc, or technically I didn't miss a case because bash has an inexplicable omission: bash doesn't source your .bashrc when you ssh in with a pty. That is, if you do:

ssh -t host command ...

Your .bashrc is not sourced. Neither does bash source your .login (well, of course).

This was an unpleasant surprise when I found it out recently, since on some of our systems we use ssh to do things that we want to interact with, and they involve commands that are not on the default $PATH. Up until recently I was counting on .bashrc to fix up that problem, which is how I came to discover the issue. (There's nothing like actually trying your plans out.)

I assume that this is caused by a misfire in the bash heuristics that try to figure out if you are ssh'ing in. Hopefully this means that it will be fixed in the future (although some of the systems affected by this are Solaris machines, which are unlikely to get new versions of bash any time soon).

(Although it might be tempting to see this as an argument against such heuristics in general, I don't agree with that position. For better or worse, bash's heuristics to source .bashrc when you ssh in give you generally useful behavior. And taking away features entirely just because they can't be implemented perfectly is not generally very helpful.)

Comments on this page:

From at 2009-05-04 02:09:29:

If I could have Bash as my login shell on Solaris at work, I might be complaining about this too. As it is, my environment does things like rsh host '. .shrc; exec [...]'

From at 2009-06-26 20:58:05:

FYI, the bash package included with Debian and derivatives (e.g. Ubuntu) ships with a patch that sources .bashrc.

Took a very long time why bash did not work the same on some Fedora and Solaris systems, but did on my Debian-powered workstations.

-- SamatJain

Written on 03 May 2009.
« Why version control systems should support 'rewriting history'
How we periodically scrub our ZFS pools »

Page tools: View Source, View Normal, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Sun May 3 23:39:40 2009
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.