12
4
I've noticed that when I run a command directly on an SSH host using the ssh <host> <command>
syntax, I see the output of .bashrc
but not the output of .bash_profile
(or .profile
).
For instance, if I place the following command at the top of both files,
echo ${BASH_SOURCE[0]}
and manually source .bash_profile
(which sources .bashrc
in turn), I'll see
$ . .bash_profile
.bash_profile
.bashrc
This is the same output I see if I log into this computer remotely via SSH, using the ssh <host>
form of the command. (And if I stow .bash_profile
somewhere else temporarily, neither of these lines gets echoed.)
However, if I execute a command directly on the remote machine with the ssh <host> <command>
form of ssh
, then the output looks like this:
$ ssh <host> echo foo
/home/rlue/.bashrc
foo
My understanding is that the difference between .bash_profile
and .bashrc
is that the former is for login shells while the latter is for interactive, non-login shells.
I've concluded the following:
ssh <host>
sources only.bash_profile
, whilessh <host> <command>
sources only.bashrc
, which means- the former is a login shell and the latter is not.
Are these conclusions correct? Why is ssh <host> <command>
treated as an interactive, non-login shell? Isn't SSH still logging into the remote machine to execute the command?
output of
.bashrc
? That file is not supposed to produce any output. Any output from.bashrc
can break all tools using ssh as their transport. – kasperd – 2017-07-02T22:57:38.597Fair enough. In this case, a couple lines in
.bashrc
were throwing an error, while similar lines in.bash_profile
were not. I took the opportunity to investigate the discrepancy before fixing the offending lines. – Ryan Lue – 2017-07-03T01:15:55.287