[last updated: 2022-12-28]
Linux home page
Linux commands
-----
---------------------------------
For:
- for (( initializer; condition; step ))
do
commands
done
- for (( c=1; c<=5; c++ ))
do
echo "Welcome $c times"
done
- list all files in directory:
for filename in *;
do
echo $filename
done
---------------------------------
While:
- while [ condition ]
do
command1
command2
command3
done
- while [ $someVar -gt 4 ]
while [ $someVar -gt $otherVar ]
- Same comparison operators for strings and numbers as listed for If statements above will work for while condition.
---------------------------------
Break statement:
Use break whenever you want to force your program execution to leave a for- or while-loop before its end.
You can also specify to break out of multiple loops using:
break 2 ... for 2 loops for example
---------------------------------
.
.
.
eof