TMUX setting environment variables for sessions

后端 未结 4 1771
故里飘歌
故里飘歌 2021-02-04 00:07

I work in a situation where I have multiple projects and within each are many scripts that make use of environment variables set to values specific to that project.

What

4条回答
  •  忘了有多久
    2021-02-04 00:19

    You can access tmux (local) environment variables for each session, while in a session, with the command:

    bash> tmux show-environment
    

    If you add the -g parameter you get the environment for all sessions, i.e. the global environment. The local environments are NOT the same as the global environment. The previous command prints the entire local environment, but you can also look at just one variable:

    bash> tmux show-environment variable_name
              variable_name=value
    

    To get the value, you could use some 'sed' magic or use 'export' on a single variable, or you can even 'export' the entire environment to your shell. Below are the 3 approaches.

    bash> tmux show-environment variable_name | sed "s:^.*=::"
             value
    
    bash> eval "export $(tmux show-environment variable_name)"
    bash> echo $variable_name
             value    
    
    bash> for var in $(tmux show-environment | grep -v "^-"); do eval "export $var"; done;
    bash> echo $variable_name
             value    
    

    If needed, you can just add the -g parameter after the show-environment command if you want to access the global environment.

提交回复
热议问题