Is there a way to make a bash script run only when the first terminal in the session is open?
Obviously sourcing it in the
~/.bashrc file doesn't answer the question.
You could use
~/.profile, which is executed when
bash is started as a login shell.
~/.bashrc may well be the answer (on a systemd system, if you can be sure that bash is used):
if ! [ -f /run/user/$UID/runonce_myscript ]; then touch /run/user/$UID/runonce_myscript /path/to/myscript fi