I want to retry a command for 5 times with an interval of 20 seconds. I want this command to be passed as a method parameter. How to do it? And once the function is written how to pass the value to the function?I want my current code to be converted to a function which takes a set of parameters. How to write and call this function in my shell script?My current code is like this :   trialNumber=0    until [ $trialNumber -ge 5]       do        ssh $USERID@$HOST $SCRIPT_LOCATION/runme.sh   # This line is my command and it may very with number of parameters or command itself.       [ $? -eq 0 ] && break      trialNumber=$[$trialNumber+1]      sleep 20   done( Above code is embedded at many places I want to move it into a function).
Converting a loop of code to function
shell;shell script;function
retry() {  trialNumber=$1 delay=$2; shift 2  while [ $trialNumber -gt 0 ]; do    $@ && return    ret=$?    sleep $delay    trialNumber=$(($trialNumber - 1))  done  return $ret}retry 5 20 ssh $USERID@$HOST $SCRIPT_LOCATION/runme.shThough the last sleep in case of failure is not necessary. May be better as:retry() {  trialNumber=$1 delay=$2; shift 2  until $@; do    ret=$?    trialNumber=$(($trialNumber - 1))    [ $trialNumber -gt 0 ] || return $ret    sleep $delay  done}