https://github.com/ltratt/try_repeat
Run a command 'n' times, exiting early if the command returns non-zero
https://github.com/ltratt/try_repeat
shell unix
Last synced: 8 months ago
JSON representation
Run a command 'n' times, exiting early if the command returns non-zero
- Host: GitHub
- URL: https://github.com/ltratt/try_repeat
- Owner: ltratt
- License: other
- Created: 2023-01-25T10:25:18.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2025-03-14T15:24:03.000Z (over 1 year ago)
- Last Synced: 2025-03-14T16:29:14.159Z (over 1 year ago)
- Topics: shell, unix
- Language: Roff
- Homepage: https://tratt.net/laurie/src/try_repeat/
- Size: 17.6 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# try_repeat
`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.
# Usage
```sh
try_repeat [-ehv] [ ... ]
```
Options:
* `-e` Sets an environment variable `TRY_REPEAT_I` with the current execution
number. Starts at 1.
* `-v` Print out the iteration number before executing ``.
`try_repeat` exits with the exit code of the last iteration of ``.
# Examples
```sh
$ 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
```