construct allows to repeat for a given number of times a code block code1
. The number of the current cycle is saved in current_cycle
. After in
you can write which numbers the variable current_cycle
must assume. The structure is:
for current_cycle in 1 2 3 4 5; do
For example, to cycle 5 times, you can write:
# This script executes 5 cycles in which the variable
# current_variable takes the values 1, 2, 3, 5, 10
for current_variable in 1 2 3 5 10; do
echo "Current cycle: $current_variable"
A special element is the asterisk (*). It allows to execute for
as many times as the number of files contained in the current folder.