#!/bin/sh -e

if [ "$#" -lt 1 ]; then
  echo "Runs a command in a loop repeatedly until it fails." >&2
  echo >&2
  echo "Usage: $(basename "$0") [delay] command..." >&2
  exit 1
fi

DELAY=0
if echo "$1" | grep -q -E '^[0-9]+(\.[0-9]+)?$'; then
  DELAY="$1"
  shift
fi

while true; do
  "$@"
  sleep "${DELAY}"
done
