Search code examples
bashbackground-process

Bash - Run 3rd script after previous 2 are complete


I have the following bash script that runs 3 php scripts in order and only starts the next script once the previous one is complete:

#!/bin/bash
php -f one.php &&
php -f two.php &&
php -f three.php

However, one.php and two.php don't rely on each other and it would be faster if they ran simultaneously. Is it possible to do the following?

run one.php and two.php
once one.php and two.php are complete, run three.php

Solution

  • Put 2 processes in background, wait for them and then run third one:

    php -f one.php &
    php -f two.php &
    wait
    php -f three.php