# To: chet@ins.CWRU.Edu # Subject: Bash functions # From: Sandeep Mehta ########################################## # # repeat - clone of C shell builtin `repeat' # # usage: repeat # # It has been tested inside other functions and in conditionals like # if [ "`repeat `" ]; then COMMANDS [ else COMMANDS ] fi # Please send me fixes/enhancements. # # Sandeep Mehta ########################################## repeat() { local rcount=$1 if [ $# -le 1 ] || [ -z "$rcount" ]; then echo "usage: repeat " 1>&2 return 2 fi shift local acmd=("$@") if [ $rcount -le 0 ]; then echo "count must be greater than 0" echo "usage: repeat " 1>&2 return 2 fi st=0 while [ $rcount -gt 0 ]; do eval "${acmd[@]}" st=$? rcount=$((rcount - 1)) done return $st }