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