Last day, I needed to repeat a shell command a arbitrary number of times, and all I found was the suggestion to use the repeat command.

Sadly, I haven’t been able to found that command in Ubuntu, but after some research I could luckily find something useful. What follows is a very simple bash implementation of the repeat command.

First, open your .bash_aliases file:

xdg-open ~/.bash-aliases

Second, paste these lines at the bottom of the file and save:

repeat() {
    n=$1
    shift
    while [ $(( n -= 1 )) -ge 0 ]
    do
        "$@"
    done
}

Third, either close and open again your terminal, or type:

source ~/.bash_aliases

Et voilà ! You can now use it like this:

repeat 5 echo Hello World !!!

or

repeat 5 ./myscript.sh

Hope this can help you !