2

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.

1

You could use ~/.profile, which is executed when bash is started as a login shell.

1

~/.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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.