From 772f20abb0a3a0979c440114bf3a1cff5b3cef03 Mon Sep 17 00:00:00 2001 From: cvpcs Date: Wed, 2 Jun 2010 11:02:31 -0500 Subject: initial import of bash 4.1 --- examples/functions/repeat2 | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 examples/functions/repeat2 (limited to 'examples/functions/repeat2') diff --git a/examples/functions/repeat2 b/examples/functions/repeat2 new file mode 100644 index 0000000..2e2dc7a --- /dev/null +++ b/examples/functions/repeat2 @@ -0,0 +1,43 @@ +# 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 +} -- cgit v1.1