Skip to main content
added 726 characters in body
Source Link
yarl
  • 520
  • 3
  • 8

As far as I understand reading the manual, this is the intended behavior.

When the server is (automatically) launched when you create your first session, the global environment is indeed created and get the TEST variable.

Why do you think that when you create the second session, the session environment will get TEST.

To set a session environment, you can use set-environment.

#!/bin/bash tmux new-session -d -s $1 tmux set-environment -t $1 TEST $1 

run it

./test.sh 123 ./test.sh 555 

then you can look an environment using show-environment

tmux show-environment -t 123 TEST tmux show-environment -t 555 TEST 

EDIT

Window 0 created at new-session and thus does not get env set using set-environment.

I agree this is weird.

I think what you want can be achieve with (something like) this is .bashrc:

if [ -n "$TMUX" -a -n "$ENVFILE" ]; then source $ENVFILE fi 

and newsess.sh:

#!/bin/bash sname=`basename $1` tmux new-session -d -s $sname "ENVFILE=$1 bash" tmux set-environment -t $sname ENVFILE $1 

/tmp/env:

export A=1 export B=2 

/tmp/env2:

export A=5 export B=5 

then

./newsess.sh /tmp/env ./newsess.sh /tmp/env2 

You got A=1 and B=2 in each window of session env and A=5 and B=5 in each window of session env2.

As far as I understand reading the manual, this is the intended behavior.

When the server is (automatically) launched when you create your first session, the global environment is indeed created and get the TEST variable.

Why do you think that when you create the second session, the session environment will get TEST.

To set a session environment, you can use set-environment.

#!/bin/bash tmux new-session -d -s $1 tmux set-environment -t $1 TEST $1 

run it

./test.sh 123 ./test.sh 555 

then you can look an environment using show-environment

tmux show-environment -t 123 TEST tmux show-environment -t 555 TEST 

As far as I understand reading the manual, this is the intended behavior.

When the server is (automatically) launched when you create your first session, the global environment is indeed created and get the TEST variable.

Why do you think that when you create the second session, the session environment will get TEST.

To set a session environment, you can use set-environment.

#!/bin/bash tmux new-session -d -s $1 tmux set-environment -t $1 TEST $1 

run it

./test.sh 123 ./test.sh 555 

then you can look an environment using show-environment

tmux show-environment -t 123 TEST tmux show-environment -t 555 TEST 

EDIT

Window 0 created at new-session and thus does not get env set using set-environment.

I agree this is weird.

I think what you want can be achieve with (something like) this is .bashrc:

if [ -n "$TMUX" -a -n "$ENVFILE" ]; then source $ENVFILE fi 

and newsess.sh:

#!/bin/bash sname=`basename $1` tmux new-session -d -s $sname "ENVFILE=$1 bash" tmux set-environment -t $sname ENVFILE $1 

/tmp/env:

export A=1 export B=2 

/tmp/env2:

export A=5 export B=5 

then

./newsess.sh /tmp/env ./newsess.sh /tmp/env2 

You got A=1 and B=2 in each window of session env and A=5 and B=5 in each window of session env2.

Source Link
yarl
  • 520
  • 3
  • 8

As far as I understand reading the manual, this is the intended behavior.

When the server is (automatically) launched when you create your first session, the global environment is indeed created and get the TEST variable.

Why do you think that when you create the second session, the session environment will get TEST.

To set a session environment, you can use set-environment.

#!/bin/bash tmux new-session -d -s $1 tmux set-environment -t $1 TEST $1 

run it

./test.sh 123 ./test.sh 555 

then you can look an environment using show-environment

tmux show-environment -t 123 TEST tmux show-environment -t 555 TEST