Advertisement

The for loop in Linux
Administration Notes

Quicklist:

for X in 1 2 3; do echo $X; done
for X in /tmp/*; do echo ls -l /tmp/$X; done
for X in 1 2 3; do echo num${X}oftotal; done

     for X in 1 2 3; do
          echo $X
     done

Command Line mode:

#Listing all the parameters
for X in 1 2 3; do echo $X; done
Output:
1
2
3
#Using filenames as parameters
for X in /tmp/*; do echo ls -l /tmp/$X; done
#When characters immediately follow the variable name, #you may should use curly braces to separate the variable from the text:
for X in 1 2 3; do echo num${X}oftotal; done
Output:
   num1oftotal
   num2oftotal
   num3oftotal

Script Mode:

for X in 1 2 3; do
     echo $X
done