Standard UNIX tool to repeat a command any number of times

command lineunix

This is probably dead easy, but is there a simple way to write a command once in the console, and have it executed n times, where n is specified at runtime? Something like this:

repeat 100 echo hello

Does such command exist (assume typical Linux installation)?

Or would I write to do some kind of loop in bash?

Best Answer

Yes this is possible. Bash has a very extensive scripting language. In this case:

for i in {1..100}; do echo 'hello'; done

More looping examples: http://www.cyberciti.biz/faq/bash-for-loop/
Full bash reference: http://www.gnu.org/software/bash/manual/bashref.html

Related Question