1

I want to run a script from .bash_profile, but only for the first Terminal window/tab which I open. How can I prevent script execution when opening additional windows/tabs?

4
  • A separate shell binary runs in each of the windows. Wich problem are you trying to solve here?
    – nohillside
    Jul 6, 2021 at 14:27
  • @nohillside I want to launch a script from .bash_profile but only from the first terminal shell
    – Puzzled
    Jul 6, 2021 at 15:07
  • Does the script start another application in the background then, or similar?
    – nohillside
    Jul 6, 2021 at 15:11
  • @nohillside yes it does
    – Puzzled
    Jul 6, 2021 at 15:13

1 Answer 1

1

If this script starts an application/binary, the usual way to prevent several executions is to first check whether that binary is already running (man ps or man psgrep might help) and only launch it if it isn't already started.

As an alternative you could look into LaunchAgents to start the binary directly when you log in (and even have it restarted automatically in case it crashes).

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .