EN
Bash - repeat a command N times
0
points
This article will show you how to repeat command N times in Bash.
Quick solution:
#!/bin/bash
for i in {1..N}
do
<your commands>
done
or:
#!/bin/bash
for ((i = 0; i < N; i++))
do
<your commands>
done
Practical examples
Example 1
#!/bin/bash
character="+"
for i in {1..5}
do
echo -n "$character"
done
Output:
+++++
Example 2
#!/bin/bash
for i in {1..3}
do
date
done
Output:
Mon Jun 28 18:01:18 UTC 2021
Mon Jun 28 18:01:18 UTC 2021
Mon Jun 28 18:01:18 UTC 2021