Starting a new tmux session and detaching it, all inside a shell script
You are using the -d
switch when creating the session. This means that the session will start detached, so you don't need to use the detach command. Besides, if your session is not running when you try to detach, it means that it no longer exists, so your command probably exited.