In this article, we will see how to use FOR loops in an easy FOR loop example in bash.
FOR loops work similar to FOR loops in other programming languages. It executes statement or statements of code with iteration. In this FOR loop example in bash, we will use C-style FOR loop.
Lets look to its syntax.
for ((initial; condition ; iteratiom));
do
echo $i
done
Lets see it in bash shell scripting example.
As above output indicates, we created a variable and a FOR loop in bash. Variable starts with initial value as "0". Each cycle, it iterates oand echo it to terminal. Notice that the total iteration is 9 times, as condition is "i<10".