How to modify environment variables before executing a command

Malte Forkel malte.forkel at berlin.de
Thu Dec 3 08:22:25 EST 2009


Douglas E. Engert schrieb:
> 
> SSH will set the SSH_CLIENT, SSH_TTY and SSH_CONNECTION
> So you can tell if this is an ssh session.
> 
> ~./.bashrc is always run, and $- on my Ubuntu is hBc
> the first time. If its interactive, ~/.bash_profile is then run and
> $- is himBH.
> 
> Some systems might run /etc/profile as well, so tests are needed
> try echo $-
> 
> So your .bashrc could test for SSH_CLIENT,and $- for c
> and set what it wants. It could also set MY_ENV_HAS_BEEN_SET=1
> so you only run you code once at the start of a session.
> 

You're right. That way I wouldn't have to set a flag in
.ssh/environment. But I'm still somewhat reluctant to put ssh-specific
code into .bashrc which does not seem to be meant for non-interactive
shells while I don't unterstand why the ssh-specific configuration files
can't export variables.

Malte



More information about the openssh-unix-dev mailing list