Skip to content

Instantly share code, notes, and snippets.

@ThinaticSystem
Last active January 7, 2025 16:45
Show Gist options
  • Save ThinaticSystem/9229605d12f075e0751de3de4746d765 to your computer and use it in GitHub Desktop.
Save ThinaticSystem/9229605d12f075e0751de3de4746d765 to your computer and use it in GitHub Desktop.
複数コマンドの並行実行 w/ 失敗時の実行中プロセス後片付け (Bash)
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
on_some_job_error() {
kill "$(jobs -pr)"
exit 1
}
trap 'on_some_job_error' ERR
command1 &
command2 &
wait
echo 'All commands success'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment