try_repeat released

January 25 2023

Blog archive

 
Last 10 blog posts
Distinguishing an Interpreter from a Compiler
try_repeat released
Why We Need to Know LR and Recursive Descent Parsing Techniques
Compiled and Interpreted Languages: Two Ways of Saying Tomato
Software Security Research Position
How Might Generative AI Change Programming?
pizauth: differentiating transient from permanent errors
November Links
More Evidence for Problems in VM Warmup
What is a Research Summer School?
 
One of the great things about Unix is the ability for users to add small tools that fit in seamlessly with those provided by the base operating system. I've written a few such tools over the years.

Today I'm releasing another little Unix tool try_repeat, which tries to run a command n times, exiting early if the command exits with a non-zero exit code. Think of it a bit like the repeat command built into some shells (e.g. zsh) but which "exits as soon as an execution of the command fails". This is particularly useful when trying to find intermittent failures in a command: I can set an upper bound (i.e. "if the command runs n times successfully, I'll assume there are no problems") but be notified if there are any problems earlier on.

I've had a basic version of this command knocking around in my bin/ directory for quite a while. Earlier today I was trying to debug a non-deterministic failure and fiddling around with unwieldy shell commands. Once I rediscovered try_repeat, it allowed me to quickly hunt down the non-deterministic failure, fix it, and feel confident that I'd fixed it.

That was all the motivation I needed to tidy things up, extend them a bit, and make a formal release. With a new name [1], I've now released try_repeat 0.1.0.

try_repeat is a deliberately simple tool as you can see from the examples:

$ try_repeat -h
Usage: try_repeat [-hv] <count> <command> [<arg1> ... <argn>]
$ try_repeat 3 ls /etc/motd
/etc/motd
/etc/motd
/etc/motd
$ echo $?
0
$ try_repeat 3 ls /doesntexist
ls: /doesntexist: No such file or directory
$ echo $?
1
$ try_repeat -v 3 ls /etc/motd
===> 1: ls /etc/motd
/etc/motd
===> 2: ls /etc/motd
/etc/motd
===> 3: ls /etc/motd
/etc/motd
As with the first release of any bit of software, I can't promise that try_repeat is perfect, so please let me know of any problems!

If you’d like updates on new blog posts: follow me on Mastodon or Twitter; or subscribe to the RSS feed; or subscribe to email updates:

Footnotes

[1] This tool was originally called repeat_or but Edd Barrett came up with the much better name of try_repeat.
This tool was originally called repeat_or but Edd Barrett came up with the much better name of try_repeat.

Comments

Comment:
Name:
Homepage: (optional)
Email: (used only to verify your comment: it is not displayed)
Can't load comments