Keep retrying a bash command until it fails
Aug 5, 2024·
·
1 min read

Gert de Pagter
This week I noticed a test was flaky, and was occasionally failing in CI. So I wanted to re-run my script until it failed.
I had no clue how to do this, so after a bit of trying, I got the following script. This keeps running vendor/bin/phpunit
until it fails. You can save it as run.sh
and then just run sh ./run.sh
in your terminal, and it will keep running.
#!/bin/sh
set -e
while [ true ] do
vendor/bin/phpunit
done
If you want to get notified of the next blog post, join the newsletter.