Skip to content

Instantly share code, notes, and snippets.

@bhurlow
Created September 13, 2019 15:25
Show Gist options
  • Save bhurlow/21362b39579fc1f0d1b0401affeb05fc to your computer and use it in GitHub Desktop.
Save bhurlow/21362b39579fc1f0d1b0401affeb05fc to your computer and use it in GitHub Desktop.
async bash example
#! /bin/bash
cust_func(){
echo "Do something $1 times..."
sleep 1
}
# For loop 5 times
for i in {1..5}
do
sleep 5 &
# cust_func $i & # Put a function in the background
done
jobs
## Put all cust_func in the background and bash
## would wait until those are completed
## before displaying all done message
wait
echo "All done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment