|
|
|
|
|
by chubot
3446 days ago
|
|
Shell and bash are actually excellent at this, but people don't like writing shell scripts. This is just process chaining. Take a look at DJB's or the more modern runit for init toolkits that compose. https://cr.yp.to/daemontools.html http://smarden.org/runit/ Here is a bash function that retries N times: retry() {
local n=$1
shift
for i in $(seq $n); do
"$@"
done
}
retry 5 echo hi
Then you can compose with a timeout function, which already exists: timeout-demo() {
timeout 0.1 $0 retry 5 echo hi
}
You can pass the names of other functions as pre and post hooks as well.https://www.gnu.org/software/coreutils/manual/html_node/time... Shell has a very forth-like quality to it, and Forth is sort of like a backwards Lisp as well (postfix rather than prefix). |
|
IMO Bash with it's multitude of annoying quoting and field splitting rules, many irrelevant features focusing on interactive use, and error handling as an afterthought is just wrong choice for writing robust systems. It's too easy to make mistakes. And it still works only in the simplest cases, until somebody evil deliberately pass you newline delimited string or something with patterns which expands in unexpected place, etc. Properly handling those cases will make your script ugly mess. Actually I find the mental burden when writing shell scripts is very akin to programming in C.