When I ssh into my ubuntu-box running Hardy 8.04, the environment variables in my .bashrc
are not set.
If I do a source .bashrc
, the variables are properly set, and all is well.
How come .bashrc
isn't run at login?
bashrc is sourced when you SSH in, by default.
A bashrc file is shell script that Bash runs whenever it is started. Along with setting in the OS, the bashrc helps determine how your command line interface (CLI) or Terminal app looks and acts.
bash_profile is read and executed when Bash is invoked as an interactive login shell, while . bashrc is executed for an interactive non-login shell. Use . bash_profile to run commands that should run only once, such as customizing the $PATH environment variable .
.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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With