Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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.


Up 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#intention...


Note 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


I like this solution better, no bash running a string command.

Could easily prefix eventually_succeeds with timeout.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: