Bob van Luijt Bob van Luijt - 3 months ago 16
Linux Question

How to run a command in bash which captures the output and waits until the command has finished?

I am using the following in a bash script:

command >> /var/log/somelog.log 2>&1&

The reason I'm doing this is because I want to capture all output in

This works fine. However it does not wait until the command has finished. So that brings me to the question, how can I capture all output from
and not have the bash script continue before
has finished?


Don't put the command in the background.

The last & character means "run this command in the background, while giving me a new shell prompt immediately."

command >> /var/log/somelog.log 2>&1&
                                    ^ this one

Just take that last character off the command, and the command will run in the foreground until it finishes.

This is frankly pretty introductory stuff. Have you considered reading any documentation about using the shell?