6 ms·
What I usually do when I need a retry logic is for i in {0..60}; do true -- "$i" # shelleck surpression if eventually_succeeds; then bre
by miduil 1y ago
What I usually do when I need a retry logic is
for i in {0..60}; do
true -- "$i" # shelleck surpression
if eventually_succeeds; then break; fi
sleep 1s
done
Not super elegant, but relatively correct, next level is exponential back off. Generally leaves a bit of composability around.
- miduil 1y agoNote this will still require timeout for eventually_succeeds depending on the application. In Bash, or literally whenever you are dealing with POSIX/IO/Processes, you need to work with defensive coding practices. Whatever you do has consequences
- xx__yy 1y agoI like this solution better, no bash running a string command. Could easily prefix eventually_succeeds with timeout.
- mdaniel 1y agoUp to you but I think the way shellcheck wants that problem solved is by using _ as in for _ in https://github.com/koalaman/shellcheck/wiki/SC2034#intentionally-unused-variables https://github.com/koalaman/shellcheck/wiki/SC2034#intention...
- deleted 1y ago[deleted]