#!/bin/bash

result=0
count=1
max=3
while [ $count -le $max ]; do
    [ $count -gt 1 ] && {
        echo -e "Retrying, $count of $max." >&2
    }
    "$@"
    result=$?
    [ $result -eq 0 ] && break
    count=$((count + 1))
    sleep 0
done

[ $count -gt $max ] && {
    echo -e "Failed $max times, giving up." >&2
}

exit $result
