Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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
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
up vote 9 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


if [ -n "$TMUX" ]; then
    # called inside tmux session, do tmux things
share|improve this answer
One could arrive at such knowledge by comparing 'printenv' output. – user1133275 Mar 28 '15 at 4:15

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

share|improve this answer

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.