Sign up ×
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'm using tmux from a while and I'm very happy with it. Since I need it most of the time, I made it my default shell (in guake, to be precise).

This is nice and I'm perfectly fine with this.

But from time to time, I need to exit tmux and having a clean shell, but since I'm defaulted with tmux, terminating the session will result in another tmux later.

So, my question is: is it possible to replace the tmux process with a given shell?

Something like exec which, of course, doesn't work, because it replacess the shell inside tmux and not tmux itself.

share|improve this question
Since you only made tmux default in quake you could always just fire up an xterm/gnome-terminal/Terminal and that'll use your system default shell (which you seem to indicate you haven't changed). Of, for that matter, even if you did change your system shell, using the -e option in xterm (similar in other terminal programs) you could specify the shell to run in the terminal. e.g.: xterm -e /bin/bash – SuperMagic Mar 7 '13 at 16:01
Thanks, this is what I usually do when I'm on a local machine, but sometimes I need to do the same task on remote ones where tmux is my system default. – AkiRoss Mar 7 '13 at 16:07
well, then.... after already logged into the remote machine I don't know of anyway to do this without X. You can use the same technique with ssh: "ssh you@remote /bin/bash" and it'll run bash rather than your default shell. Alas, this probably still doesn't solve your problem. – SuperMagic Mar 7 '13 at 16:40

2 Answers 2

up vote 2 down vote accepted

I don't think tmux can do that. It should be easy to patch if you know C programming.

One thing you could do is call tmux from a wrapper shell script, and let the script decide whether to exit or not. Send a signal to the wrapper to tell it to execute an interactive shell when tmux exits. Here's an untested proof-of-concept for the wrapper script:

trap 'exec bash -i' USR1

In ~/.tmux.conf:


From within tmux, to get a shell prompt after detaching:

TMUX_PARENT_PID=$(tmux show-environment | sed -n 's/^TMUX_PARENT_PID=//p')
tmux detach-client
share|improve this answer
Nice idea to catch a signal in a wrapper script. – AkiRoss Mar 8 '13 at 12:02

If tmux is running, environment variable TMUX would be set, thus by putting lines like this in your bashrc, tmux would still be your shell.

But if it's already running, bash or other shell would run normally, (don't use chsh to set your shell to tmux, that can be a problem)

if [[ ! -z ${TMUX} ]]; then
    // run tmux
    tmux "$@"
    exit 0
// tmux is already running
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.