0

For explaining I use Firefox, but it also happens with other applications, here's the script:

$ cat ff.sh
#!/bin/sh
firefox http://superuser.com/
echo "$?"

Let's say Firefox is closed, when I run

$ ./ff.sh

the script is blocked until I close Firefox. Only after that I get the exit code.

0

$ 

Now let's say Firefox is already running, when I run the script it opens a new Firefox tab and runs through to the end. (And Firefox keeps running.)

$ ./ff.sh
0

$ 

How can I achieve that the behaviour is the same as in the first example regardless of the start condition? Basically I want to achieve the opposite of

$ cmd &
816-8055
  • 1,176
  • 1
  • 8
  • 12

1 Answers1

0

It looks as if it ran asynchronously while in fact it did not.
When firefox launches it checks for existing instance, if found it delegates control to existing instance and ends itself. Hence the confusion.

guest
  • 3,359
  • 17
  • 27
  • Ok, that makes sense. So then I have to find a new solution (e.g. command line option) for each application that does that, or is there a generic workaround that isn't too ugly? – 816-8055 Jun 17 '16 at 15:18
  • @816-8055 on linux, `firefox -new-instance -url http://superuser.com` should work. given my experience with linux is mostly bash script, i am unaware of any generic fix. on windows, singleton can usually be bypassed with sandboxie. – guest Jun 17 '16 at 17:13
  • related questions: [#1](http://superuser.com/questions/165937/run-multiple-instance-of-any-windows-application), [#2](http://serverfault.com/questions/426267/enable-a-program-in-windows-to-run-multiple-times) – guest Jun 17 '16 at 17:15