≡ Menu

Linux bash for loop

Q. How do I use bash for loop under Linux operating systems?

A. for loop is used to process group of files or for other automation purposes.

Linux bash for loop syntax

for variable in list
   echo $variable

To loop through all files in a directory, enter:

for file in *
   echo $file

To print number 1 to 10, enter:

for n in {1..10}
   echo $n

Shell script to print odd and even number using a for loop

for n in {1..10}
   out=$(( $n % 2 ))
   if [ $out -eq 0 ] 
	echo "$n is even number"
	echo "$n is ODD number"	

See more bash for loop examples here.

Share this tutorial on:
{ 1 comment… add one }
  • Mosco February 10, 2012, 5:09 am

    My Epson CX3810 works out of the box with no fuss, that is the ptnerir and the scanner part.. Faxing should also work, tho I have not tried it. I recently moved the ptnerir to an Ubuntu home and shared it out and I can to it on my Linux boxes and Windows and even my old Mac PPC G4 tower running OS 10.5.. Of course the Windows (XP/Vista and 7) all needed drivers and so did the Mac..Just in case anyone wanted to know.

Security: Are you a robot or human?

Leave a Comment

You can use these HTML tags and attributes: <strong> <em> <pre> <code> <a href="" title="">

   Tagged with: , , , , , , , , , , , ,