diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-06-03 01:37:36 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-06-03 01:37:50 +1200 |
commit | f095526805fd347c23bf0a9e27609a6949051616 (patch) | |
tree | 7018ddc7c7f5e275daabc410f9f0588dcaabe9da /bin/rep.sh | |
parent | Use full length($0) rather than just length (diff) | |
download | dotfiles-f095526805fd347c23bf0a9e27609a6949051616.tar.gz dotfiles-f095526805fd347c23bf0a9e27609a6949051616.zip |
Add rep(1df)
Diffstat (limited to 'bin/rep.sh')
-rw-r--r-- | bin/rep.sh | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/bin/rep.sh b/bin/rep.sh new file mode 100644 index 00000000..e53cbac3 --- /dev/null +++ b/bin/rep.sh @@ -0,0 +1,25 @@ +# Repeat a command +self=rep + +# Check arguments. +if [ "$#" -lt 2 ] ; then + printf >&2 '%s: Need a count and a program name\n' "$self" + exit 2 +fi + +# Shift off the repetition count. +c=$1 +shift + +# Check the repetition count looks sane. Zero is fine! +if [ "$c" -lt 0 ] ; then + printf >&2 '%s: Nonsensical negative count\n' "$self" + exit 2 +fi + +# Run the command the specified number of times. Stop immediately as soon as a +# run fails. +while [ "${n=1}" -le "$c" ] ; do + "$@" || exit + n=$((n+1)) +done |