Reputation: 5807
I'm simply trying to set a shell env for a tmux session. At first it works like expected:
export MY_VARIABLE=123
tmux new-session
# in session
echo $MY_VARIABLE
-> 123
Now I detach the session and create a second one:
tmux detach
echo $MY_VARIABLE
-> 123
export MY_VARIABLE=456
echo $MY_VARIABLE
-> 456
tmux new-session
# in new session
echo $MY_VARIABLE
-> 123
# list session to see it is really a new one
tmux list-sessions
-> 0: 1 windows ...
-> 1: 1 windows ... (attached)
If I exit the old session (not detach), then it works as expected. It looks like the variables are synced between sessions? How can I break this up to have separate $MY_VARIABLE after starting a tmux session?
Upvotes: 2
Views: 481
Reputation: 5807
Looks like this is a feature of tmux: variable sharing. By connecting to different sockets, different variables can be set (found out by this stackexchange question):
export MY_VARIABLE=123
tmux -L socket_name new-session
# in session
echo $MY_VARIABLE
-> 123
tmux -L socket_name detach
export MY_VARIABLE=456
tmux -L another_socket new-session
# in new session
echo $MY_VARIABLE
-> 456
Upvotes: 2