Skip to content

Instantly share code, notes, and snippets.

@RWJMurphy
Created September 23, 2013 02:10
Show Gist options
  • Select an option

  • Save RWJMurphy/6665733 to your computer and use it in GitHub Desktop.

Select an option

Save RWJMurphy/6665733 to your computer and use it in GitHub Desktop.
function retry() {
# retry [--limit,-l] [--delay,-d] [--] command args..
[ $# -lt 1 ] && echo "return [-ld] [--] commands [args...]" >&2 && return
LIMIT=5
DELAY=5
while [[ $# > 0 ]]; do
case $1 in
--limit|-l)
shift
LIMIT=$1
;;
--delay|-d)
shift
DELAY=$1
;;
--)
shift
break
;;
*)
break
;;
esac
shift
done
command=$1;shift
args="$*"
success=1
while true; do
$command $args
success=$?
[ $success -eq 0 ] && break
let LIMIT--
[ $LIMIT -lt 1 ] && break
sleep $DELAY
done
}
@RWJMurphy
Copy link
Author

retry() { while true; do $* && break || sleep 10; done }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment