Skip to content

Instantly share code, notes, and snippets.

@stevendanna
Created March 11, 2012 01:38
Show Gist options
  • Save stevendanna/2014470 to your computer and use it in GitHub Desktop.
Save stevendanna/2014470 to your computer and use it in GitHub Desktop.
do.times
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