How to modify environment variables before executing a command

Carson Gaspar carson at taltos.org
Sat Dec 5 20:42:38 EST 2009


Jim Rees wrote:

> Ssh has no problem exporting env vars, as you have discovered.  Just put
> them in .ssh/environment.  You are trying to do something bash-specific in
> your ssh config file:
> 
> VAR1=$(date)
> 
> That's not going to work.  If you want to run bash code, you have to put it
> in a bash config file, not in an ssh config file.

That's not bash-specific, that's POSIX. The "probem" is that 
.ssh/environment is not shell code, it's just a set of key/value pairs. 
Read the man page, it will help ;-)

If you want something to happen in your SSH session, and don't want it 
to happen during normal shells, why don't you just ask for it in your 
remote command? e.g. instead of doing "ssh myserver mycmd" do "ssh 
myserver 'source myconfig && mycmd'". Otherwise modify your shell config 
as many other folks have said, making its execution conditional on its 
environment.


More information about the openssh-unix-dev mailing list