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.)

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

Page tools: View Source, Add Comment.
Search:
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.