I have the following problem:
$ some_command & # Adds a new job as a background process
$ wait && echo Foo # Blocks until some_command is finished
$ wait && echo Foo & # Is started as a background job and is done immediately
What I would like wait &
to do is to wait in the background until all other background jobs are finished.
Any way I can achieve that?
Best Answer
At some point, something has to wait for the execution of commands.
However, if you could place your commands inside a couple of functions, you can schedule them to do what you need:
If the sleep times are as shown in the code, 3 and 5, then some_command will end before the rest of the jobs, and this will be printed on execution:
If the sleep times are (for example) 8 and 5, this will be printed:
Note the order. Also the fact that each part has ended as soon as it was possible for itself (the value of
$SECONDS
printed).