Skip to content

Instantly share code, notes, and snippets.

@justin808
Created June 4, 2018 00:21
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save justin808/67276efe955b2a44a5489444807332ed to your computer and use it in GitHub Desktop.
Simple bash script to run multiple tasks concurrently
#!/usr/bin/env bash
# Edit the list of commands.
# YOU MUST USE SINGLE QUOTES HERE.
commands=(
'yarn run build:client-bundles:prod'
'yarn run build:server-bundle:prod'
'yarn run build:global-styles:prod'
)
################################################################################
# DO NOT TOUCH BELOW THIS LINE
################################################################################
pids=""
# Run concurrent processes
for command in "${commands[@]}"; do
echo command is ${command}
( ${command} ) &
pid=$!
# store PID of process
pids+=" ${pid}"
echo "${pid}: Running: ${command}"
done
# Wait for all processes to finnish, will take max 14s
for p in $pids; do
if wait $p; then
echo "Process $p succeeded."
else
echo "Process $p failed. Build aborted."
echo "Killing any running concurrent commands."
kill $pids &> /dev/null
exit 1
fi
done
@shayantrix
Copy link

i want to use another variable in "commands"
like -> read -p "Enter your name: " name
commands=(
'echo "your name is $name" '
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment