I used the tmux.sh example from https://wiki.ubuntuusers.de/tmux/#Bedienung . Now I get a message "sessions should be nested with care, unset $TMUX to force" every time I start 'tmux'. But as I understand, tmux isn't nesting in this case.

My tmux.sh looks as follows now:

#tmux="tmux -2 -f ~/.tmux.conf"
tmux="tmux -2"

# if the session is already running, just attach to it.
$tmux has-session -t $SESSION
if [ $? -eq 0 ]; then
# echo "Session $SESSION already exists. Attaching."
  sleep 1
  $tmux attach -t $SESSION
  exit 0;
# create a new session, named $SESSION, and detach from it
  $tmux new-session     -n Werkbank -d  -s $SESSION
  $tmux split-window    -h              -t $SESSION:1
  $tmux new-window      -n "SysA|SysB"  -t $SESSION:2 'ssh A'
  $tmux split-window    -h              -t $SESSION:2 'ssh B'
  $tmux new-window      -n "GwA|GwB"    -t $SESSION:3
  $tmux split-window    -h              -t $SESSION:3
  $tmux select-window                   -t $SESSION:1
  $tmux attach                          -t $SESSION
  • the script looks ok and works fine for me in both cases: when the session exists or even if it doesn't . Are You sure You're not executing the script from a tmux session? Apr 1 '19 at 13:28

Adding the following to the start of your script should prevent such errors:

 # If script is run inside tmux, exit without doing anything
 if [[ -n $TMUX ]]; then
     echo "Nested tmux sessions not supported!"
     exit 0
  • anything is misspelled.
    – Alex
    Apr 14 '20 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.