try_repeat

RSS feed: whole site

try_repeat tries to run a command n times, exiting early if the command exits with a non-zero exit code. This is useful when trying to find intermittent failures in a command.

Download and docs

Latest release: try_repeat-0.2.0 (2023-01-29)

  • Use "$@" rather than eval to execute <command>. This preserves spaces in <command> (e.g. those contained in quotes), and thus, in general, tends to better match the user’s expectations about what command will actually be executed.

All releases

Repository (issues, PRs, etc.)

Man page for the latest release

All releases

Usage

try_repeat [-hv] <count> <command> [<arg1> ... <argn>]

Options:

-vPrint out the iteration number before executing <command>

try_repeat exits with the exit code of the last iteration of <command>

Examples

$ 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