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?

  • 3
    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
    Commented Jan 18, 2013 at 15:34
  • 2
    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
    Commented Oct 21, 2013 at 21:34

3 Answers 3


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
  • 1
    One could arrive at such knowledge by comparing 'printenv' output. Commented Mar 28, 2015 at 4:15
  • 2
    Is there any downside to this? I'm of the opinion that tmux should not launch shells as login shells, and while I've read vigorous debate about it elsewhere, I still haven't seen a compelling reason for it. I'm going to use this $TMUX check in my profile if for no other reason than to reduce $PATH duplication, but is there any downside? Commented Oct 31, 2016 at 17:47

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


Instead of TMUX, you can export your own. It is useful in the case there are more than one tmux users and you want to source it only for yourself.

Add the following line to ~/.tmux.conf.

if-shell shell-command export SOMEONE_USING_TMUX=1

And, add the following lines to ~/.bash_profile.

if [[ ! -z "$SOMEONE_USING_TMUX" ]]; then
    # source for yourself

You must log in to answer this question.