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 do echo $variable done
To loop through all files in a directory, enter:
for file in * do echo $file done
To print number 1 to 10, enter:
for n in {1..10} do echo $n done
Shell script to print odd and even number using a for loop
#!/bin/bash for n in {1..10} do out=$(( $n % 2 )) if [ $out -eq 0 ] then echo "$n is even number" else echo "$n is ODD number" fi done
See more bash for loop examples here.
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop













{ 1 comment… read it below or add one }
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.