Skip to content

Instantly share code, notes, and snippets.

@jessebutryn
Created February 7, 2022 16:50
Show Gist options
  • Select an option

  • Save jessebutryn/cddf67b498c96ed6ffca19e7301be793 to your computer and use it in GitHub Desktop.

Select an option

Save jessebutryn/cddf67b498c96ed6ffca19e7301be793 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
runs=$1
passorfail () {
local _thing=$1
sleep 2
if [[ $_thing == pass ]]; then
return 0
else
return 1
fi
}
for ((i=1;i<=runs;i++)); do
if (((RANDOM%10)+1>5)); then
thing=pass
else
thing=fail
fi
passorfail "$thing" &
pids+=($!)
done
for pid in "${pids[@]}"; do
if wait "$pid"; then
((passed++))
else
((failed++))
fi
done
printf 'Passed: %d\nFailed: %d\n' "$passed" "$failed"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment