![wiki.ubuntuusers.de/tmux/의 예를 기반으로 tmux.sh 스크립트에서 tmux를 시작하여 tmux 세션을 중첩합니다.](https://linux55.com/image/150999/wiki.ubuntuusers.de%2Ftmux%2F%EC%9D%98%20%EC%98%88%EB%A5%BC%20%EA%B8%B0%EB%B0%98%EC%9C%BC%EB%A1%9C%20tmux.sh%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%EC%97%90%EC%84%9C%20tmux%EB%A5%BC%20%EC%8B%9C%EC%9E%91%ED%95%98%EC%97%AC%20tmux%20%EC%84%B8%EC%85%98%EC%9D%84%20%EC%A4%91%EC%B2%A9%ED%95%A9%EB%8B%88%EB%8B%A4..png)
tmux.sh 예제를 사용했습니다.https://wiki.ubuntuusers.de/tmux/#Bedienung. 이제 "tmux"를 시작할 때마다 "세션은 주의해서 중첩되어야 합니다. $TMUX를 설정 해제하여 강제로 설정해야 합니다"라는 메시지가 나타납니다. 그러나 내가 아는 한, tmux는 이 경우에 중첩되지 않습니다.
내 tmux.sh는 이제 다음과 같습니다.
#!/bin/bash
SESSION=main
#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;
else
# 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
fi
답변1
스크립트 시작 부분에 다음을 추가하면 다음과 같은 오류를 방지할 수 있습니다.
# If script is run inside tmux, exit without doing anything
if [[ -n $TMUX ]]; then
echo "Nested tmux sessions not supported!"
exit 0
fi