I have the following tmux script which is executed successfully only when I navigate to /dev/shm (that is, after I do cd /dev/shm):(cat > /dev/shm/script.sh && chmod +x /dev/shm/script.sh && tmux new-session -d '/dev/shm/script.sh; rm /dev/shm/script.sh') <<-'EOF'cd /var/www/htmlwget SOME_FILEsleep 2htmux kill-sessionEOFMy question:Why would the script be executed successfully only when I navigate to /dev/shm and not from any other place in the system?Besides the fact I'm a freshman in Linux, I really didn't come with a reason a few hours, I really try to find a reason and don't have a clue.
tmux script works only inside /dev/shm
linux;tmux;session;here document
My problem was not using the command bash when executing the script. It was:tmux new-session -d '/dev/shm/script.sh; rm /dev/shm/script.sh'While it should have been:tmux new-session -d 'bash /dev/shm/script.sh; rm /dev/shm/script.sh'I now use a slightly lighter version of the script, which I find respectively easier to maintain, as in:(cat <<'PMA' > /opt/script.sh#!/bin/bashcd /var/www/htmlwget SOME_FILEsleep 2htmux kill-sessionPMAchmod +x /opt/script.shtmux new-session -d 'bash /opt/script.sh'tmux new-session -d 'rm /opt/script.sh')If you use either, make sure to replace all leading spaces to tabulations.