#!/bin/sh # restart command with a short delay after it exits. command is best specified with -- after this programs options. restart-on-end [options] -- command ... # arguments: [-n max_restart_times|-d delay_seconds] command ... # example: restart-on-end -n 3 -- echo # other possible names for this command: call-n-times, repeat max_restart_times="-1" delay=1 while test $# -gt 0 do case "$1" in -n) shift max_restart_times=$1 ;; -d) shift delay="$1" ;; --) shift break ;; -*) echo "Unknown option: $1" >&2 exit 1 ;; *) break ;; esac shift done while test "$max_restart_times" -ne 0 do "$@" if test "$max_restart_times" -gt 0 then max_restart_times=$(($max_restart_times - 1)) fi sleep $delay done