Created
March 11, 2012 01:38
-
-
Save stevendanna/2014470 to your computer and use it in GitHub Desktop.
do.times
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
error() { | |
echo "$1" >&2 | |
return 1 | |
} | |
is_integer() { | |
case "$1" in | |
''|*[!0-9]*) | |
return 1 | |
;; | |
*) | |
return 0 | |
;; | |
esac | |
} | |
do.times() { | |
local times=$1 | |
shift | |
if is_integer $times;then | |
for i in $(seq 1 $times); do | |
eval $@ | |
done | |
else | |
error "Positive integer expected as first argument" | |
fi | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment