execute multipe commands

I would like to execute multipe commands in a shell script. Please provide the commands for the below scenario:

Execute command1
if command1 is succesfull, then execute command2, command3,command4 in parallel
if command2, command3,command4 are success then run command 5

1 Like

with echo $? , you can get the exit status, if above command is successful, it should be 0.

command1
if [ $? -eq 0 ] then
  command2;commend3;command4
  another if-then-fi
fi

You can also add the exit status directly in script to control your condition.

Not as clean as rdcwayx but just to show various options and can be handy at the prompt.
You can use logical operator && after each command.
The shell executes the second command -- if and only if -- the first command returns a true (zero) exit status.

Example:

 command1 && command2 && command3 && command4 && command5

The above states if command1 is successful execute command2 if command2 successful execute command3 and so on.

Regards,
SRG

OP wanted to run jobs in parallel.

I created a dummyjob script like this:

sleep $1
exit $2

And the used array to store PIDs of the child processes and then waited for each of them and stored first non-zero exit status:

if ./dummyjob 4 0
then
    ./dummyjob 10 0 &
    j[0]=$!
    ./dummyjob 4 7 &
    j[1]=$!
    ./dummyjob 2 0 &
    j[2]=$!
    FAIL=0
    for PID in ${j
[*]}
    do
       wait $PID || FAIL=$?
    done
    echo "Result $FAIL"
else
   echo "First Job failed"
fi

Output appeared 14 seconds after job started:

Result 7