Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is it possible to use an environment variable in a tmux.conf file? I am trying to set a default-path to an environment variable. Currently what I am trying is:

set -g default-path $MYVAR

further I would like to check if $MYVAR is set already so I could do:

if($MYVAR == "") set-environment -g MYVAR /somepath/

Any ideas?

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

Yes it looks like it is possible to expand shell variables in .tmux.conf file It looks like it's not required, but a good idea to quote them, esp. I was able to do this successfully with the status bar options just now.

# In ~/.tmux.conf:
set -g status_left "$MYVAR etc: "

$ export MYVAR="Shell stuff"
$ tmux

I don't know about any 'if' or other control structures in the config, but there might be.

share|improve this answer
I cant get this to work in a tmux script file. I am sure $MYVAR is set, and I run the script and it fails. set -g default-path "$MYVAR" split-window -h it splits the window but default-path is not set to $MYVAR –  Digital Powers Jun 22 '11 at 20:57
ok i found where things are breaking down, if I set the environment variable before i run tmux then i can use it in my tmux.conf file. If i set the environment variable, either in tmux.conf using set-environment or after i am in tmux then reload the tmux.conf it doenst use my new variables I have set. Any idea why? –  Digital Powers Jun 22 '11 at 21:25
The shells you run inside tmux are child processes of tmux. Changing things inside those environments is not going to propogate back up the line to the tmux parent process. It only works the other way because tmux becomes a child of the shell you launched it from. I assume the config reload is similar in that it's launching a new child of the parent process. –  Caleb Jun 22 '11 at 21:31
thanks for the help –  Digital Powers Jun 22 '11 at 21:45
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.