I have set my zsh auto start a tmux session when there is no one, like this

 if [[ ! $TERM =~ screen ]]; then
    exec tmux

Yeah, this works fine, however when I detach the session, the terminal(I am using gnome-shell) will exit too. How do I avoid it

  • 1
    You could use tmux instead of exec, but that just raises the question of why you are using exec in the first place.
    – chepner
    May 23, 2017 at 1:19
  • 1
    @chepner Thanks, it works as I want now, after change 'exec tmux' to 'tmux'. in fact I don't known the difference between tmux and exec tmux, I just copy from somewhere in this site.
    – Fangxing
    May 23, 2017 at 1:39

1 Answer 1


Thanks for @chepner's comment, I just need to change exec tmux to tmux, because exec executes a specified command, replacing the current process rather than starting a new subprocess.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .