Bash for Loop Tutorial With Examples

Saturday, Aug 3, 2024 | 1 minute read | Update at Saturday, Aug 3, 2024

Bash for Loop

Linux bash provides for loop in order to itarete over different things in Linux and bash. We can use bash for loop in order to iterate over a command output which containts multiple items or execute a bash command with different arguments by providing arguments to for loop.

for Loop Syntaxes

The for loop has two popular syntax in order to be with bash.

for VARIABLE in 1 2 3 4 5 .. N
do
    command1
    command2
    commandN
done
for VARIABLE in File1 File2 File3 .. FileN
do
    command1
    command2
    commandN
done
for VARIABLE in $(COMMAND)
do
    command1
    command2
    commandN
done

© 2024 Linux and Python Tutorials

🌱 Powered by Hugo with theme Dream.