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 &