Search code examples
bashcygwinsh

Detailed How-to run multiple bash scripts from one bash script?


It seems simple, but I'm under the Tyranny of Syntax.

#!/bin/bash
#
./auth.sh -v -C start & ./world.sh -v -C start
exit 0

Theoretically would run the scripts in order, but they error out. I'm sure it's wrong I just need the kind and guiding hand of the collective consciousness that is the internet to correct this faltered souls ignorance.


Solution

  • As written there are two commands. The first is:

    ./auth.sh -v -C start &
    

    The ampersand & signals that the command that precedes it should be run in the background. That means that the shell does not wait for that command to complete. As soon as it can, it starts the next command:

    ./world.sh -v -C start exit 0
    

    Unless the first command completes very quickly, there will be a time that both are running in parallel.

    Other control operators

    Technically, & is called a control operator. There are a variety of useful control operators:

    • ; tells the shell to run the preceding command before preceding to the next.

    • A newline character is the same as a ;.

    • && tells the shell to run the preceding command, wait for it to finish, and only if the preceding comand returns success, run the following command.

    • || tells the shell to run the preceding command, wait for it to finish, and only if the preceding comand returns failure, run the following command.