I have a bash script:
#!/bin/bash
export TEST=$1
tmux new-session -d -s $1
tmux send-keys -t $1:0 "printenv | grep TEST" C-m
Run:
# ./test.sh 123 #The tmux server is automatically launched
# ./test.sh 555
Results:
tmux a -t 123
showsTEST=123
tmux a -t 555
showsTEST=123
instead ofTEST=555
!!!!
Why does my next TMUX sessions inherit all the environment variables of the first created session?
That's quite surprising, how can I do to stop this non-sense behavior?
https://manpages.debian.org/experimental/tmux/tmux.1.en.html#GLOBAL_AND_SESSION_ENVIRONMENT
When the server is started, tmux copies the environment into the global environment; in addition, each session has a session environment. When a window is created, the session and global environments are merged. If a variable exists in both, the value from the session environment is used.
When I first run 123
, TEST
is set GLOBAL for the tmux server. But when I run 555
, TEST=123
should be replaced by the session env, but it isn't...