.sh
extension are bash scripts.
One liner:
for i in {1..9}; do echo ${i}; done
Multiple Lines:
for i in {1..9}
do
echo ${i}
done
Different ranges:
for i in {1..9}; do echo ${i}; done
for i in apple banana cherry; do echo ${i}; done
for i in $(<Command>); do echo ${i}; done
ARR=('apple' 'banana' 'cherry')
for i in "${ARR[@]}"; do echo ${i}; done
Break and continue work as expected.
Works in the same fashion as a for-loop, however, the loop continues until the control expression is false.
For example, this command prints every line in a file:
while read line;
do
echo "$line"
done < file.txt