bashrc and .profile for password-less ssh

Nils Kassube kassube at gmx.net
Thu Sep 2 16:39:12 UTC 2010


shantanu pavgi wrote:
> I am having some issue in executing in setting values in .bashrc file
> on ssh based command execution. If I log in using SSH then bashrc is
> sourced and settings in it work.  But following doesn't work and
> returns no value: 
> {{{
> inode:~ shantanu$ ssh 192.168.174.129 "echo $CATALINA_HOME"
> }}}

Well, that command passes the value of CATALINA_HOME of your local 
machine to the ssh command which is probably not what you want. You need 
single quotes instead of double quotes or you could escape the $ with a 
backslash because now the $CATALINA_HOME is expanded by your local shell 
before it is passed to the ssh command.

Due to the end of your .bashrc file I suppose you want to see the value 
set by that file. Your second problem is at the start of the file where 
it checks if it is an interactive shell and returns if it isn't.

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

You can set PS1 and then source .bashrc with something like this:

ssh 192.168.174.129 'PS1=\$ . $HOME/.bashrc;echo $CATALINA_HOME'


Nils




More information about the ubuntu-users mailing list