2015-10-09 93 views
0

我只是試圖爲tmux會話設置shell env。起初,它像預期:tmux爲不同會話設置會話變量

export MY_VARIABLE=123 
tmux new-session 

# in session 
echo $MY_VARIABLE 
-> 123 

現在我離開會話,並創建第二個:

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) 

如果我離開舊的會話(不分離),那麼它將按預期工作。看起來變量在會話之間同步?在啓動一個tmux會話後,我怎樣才能分解$ MY_VARIABLE?

回答

0

看起來這是tmux的特性:變量共享。通過連接到不同的插座,可以設置不同的變量(通過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