Is there a better way to run a command N times in bash?

bstpierre picture bstpierre · Sep 17, 2010 · Viewed 222.7k times · Source

I occasionally run a bash command line like this:

n=0; while [[ $n -lt 10 ]]; do some_command; n=$((n+1)); done

To run some_command a number of times in a row -- 10 times in this case.

Often some_command is really a chain of commands or a pipeline.

Is there a more concise way to do this?

Answer

Joe Koberg picture Joe Koberg · Sep 17, 2010
for run in {1..10}
do
  command
done

Or as a one-liner for those that want to copy and paste easily:

for run in {1..10}; do command; done