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.

I have a script in my .bash_profile that prompts for X sessions to boot. When I launch tmux, I get this prompt that I had only intended for the TTY login.

Is there something I can put in .bash_profile that will simply run bash if it is part of tmux? That is, can I check with bash if .bash_profile is being read within tmux?

share|improve this question
2  
It appears that tmux starts login shells by default. I am not sure if there is a reason for this, but if you want to make tmux start non-login shells instead you can add set-option default-command bash to your .tmux.conf. (.bash_profile is only read by login shells; non-login shells ignore it). –  jw013 Jan 18 '13 at 15:34
1  
I asked a similar question and was redirected here. @jw013 's comment gives an effective way of changing this weird behaviour of tmux from within tmux (rather than tinkering the .*profile files), but it requires a -g flag to be effective, as in set -g default-command zsh –  Dalker Oct 21 '13 at 21:34

2 Answers 2

up vote 4 down vote accepted

tmux sets an environment variable called $TMUX, which I believe holds the location of the socket it's using. Either way you can use it in your .bash_profile to test whether or not it is being called from within tmux.

if [ -z "$TMUX" ]; then
    # not in tmux, do non-tmux things
fi

Or

if [ -n "$TMUX" ]; then
    # called inside tmux session, do tmux things
fi
share|improve this answer

I usually use $TERM to test that. screen and tmux set it to "screen" by default.

share|improve this answer

Your Answer

 
discard

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.