Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • Does this answer help? You can detect if the shell is started within tmux or not, so that should allow you to choose which scripts to run. Another option is to configure the terminal to run some other command instead of just a plain shell (instead of useing bashrc for that), though I have no idea how to do that in Gnome terminal, as I don't use Gnome terminal.
    – dirkt
    Commented Sep 27, 2020 at 10:27
  • Thank you for your reply. I tried using the solutions discussed in that post but unfortunately it did not work out for me. I will try to research what could be done through gnome terminal, but I am puzzled as to why my simple .bashrc solution doesn't work. The main question for me is how to execute a script inside tmux immediately after exec tmux is summoned. (I made some edits in my question above) Commented Sep 27, 2020 at 15:27
  • Because exec replaces the current process with the called process, so after exec, nothing in the script gets executed. Also, even if you drop exec, nothing of that will get executed "inside" tmux.
    – dirkt
    Commented Sep 27, 2020 at 17:24
  • @dirkt Thanks for the info. Would you have any suggestion on how to tackle this then? Commented Sep 27, 2020 at 18:23
  • Everything that comes after [[ -z "$TMUX" ]] && exec tmux is execute inside tmux though, e.g. [[ -z "$TMUX" ]] && exec tmux; echo "inside tmux". But after the first line the $TMUX variable is set and so I can't use that as a conditional for the echo in this example (or script in my original case) Commented Sep 27, 2020 at 18:26