Run parallel commands and fail if any of them fails

Use the following script:


#! /usr/bin/env bash
#
# Run parallel commands and fail if any of them fails.
#


set -eu


pids=()


for x in 1 2 3; do
  ls /not-a-file &
  pids+=($!)
done


for pid in \\"${pids[@]}\\"; do
  wait \\"$pid\\"
done


OR use the simpler script if no error is expected:


#!/bin/bash

sleep 2 &
sleep 3 &
sleep 1 &

wait

echo Finished.

Βαθμολογήστε αυτή τη καταχώρηση:

0 (0 Ψήφοι)