How to modify environment variables before executing a command

Pfaffel-Janser, Christian christian.pfaffel-janser at siemens.com
Mon Dec 7 06:03:13 EST 2009


Hi,

You might want to use 

   ~/.ssh/rc

See sshd(8) for details.

Christian

-----Original Message-----
From: openssh-unix-dev-bounces+christian.pfaffel-janser=siemens.com at mindrot.org on behalf of Carson Gaspar
Sent: Sat 2009-12-05 10:42
To: openssh-unix-dev at mindrot.org
Subject: Re: How to modify environment variables before executing a command
 
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 ex sshd(8ecution conditional on its 
environment.
_______________________________________________
openssh-unix-dev mailing list
openssh-unix-dev at mindrot.org
https://lists.mindrot.org/mailman/listinfo/openssh-unix-dev



More information about the openssh-unix-dev mailing list