.bashrc at ssh login

I had similar situation like Hobhouse. I wanted to use the command

ssh myhost.com 'some_command'

where some_command exists in /var/some_location.

I tried to append /var/some_location to the PATH environment variable by editing $HOME/.bashrc but that wasn't working. Because per default, .bashrc (on Ubuntu 10.4 LTS) exits early due to this piece of code:

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

Meaning if you want to change the environment for the ssh non-login shell, you should add code above that line.


For an excellent resource on how bash invocation works, what dotfiles do what, and how you should use/configure them, read this:

  • DotFiles

.bashrc is not sourced when you log in using SSH. You need to source it in your .bash_profile like this:

if [ -f ~/.bashrc ]; then
  . ~/.bashrc
fi

Tags:

Bash

Ubuntu

Ssh