Skip to content

Instantly share code, notes, and snippets.

@DevGW
Created February 11, 2023 14:30
Show Gist options
  • Save DevGW/a00ceedec3881e336123909eb98387d4 to your computer and use it in GitHub Desktop.
Save DevGW/a00ceedec3881e336123909eb98387d4 to your computer and use it in GitHub Desktop.
#bash wait do while waiting for jobs to end
#!/usr/bin/bash
echo "starting"
sleep 2 &
sleep 4 &
sleep 6 &
sleep 8 &
while true; do
JOBS=`jobs -p | wc -l`
# workaround about jobs bug. If don't execute it explicitily,
# JOBS will stick at 1, even when no jobs are running anymore.
jobs &>/dev/null
if [ $JOBS -ne 0 ]; then
printf "."
else
printf "\n"
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment