for loop in linux code example
Example 1: for loop in shell script
for i in {1..5}
do
echo "Welcome $i times"
done
Example 2: for in bash
for i in {0..100..10}
do
echo $i
done
will print
Example 3: for in loop javascript
var person = {"name":"taylor","age":31};
for (property in person) {
console.log(property,person[property]);
}
//name taylor
//age 31
Example 4: bash for loop
for VARIABLE in file1 file2 file3
do
command1 on $VARIABLE
command2
commandN
done
Example 5: bash script loop
while [ <some test> ]
do
<commands>
done
Example 6: for loop iteration in shell script
#!/bin/bash
START=1
END=5
echo "Countdown"
for (( c=$START; c<=$END; c++ ))
do
echo -n "$c "
sleep 1
done
echo
echo "Boom!"