Reader small image

You're reading from  Linux Command Line and Shell Scripting Bible - Third Edition

Product typeBook
Published inJan 2015
PublisherWiley
ISBN-139781118983843
Edition3rd Edition
Tools
Right arrow
Authors (2):
Richard Blum
Richard Blum
author image
Richard Blum

Richard Blum has more than 25 years as a network and systems administrator, currently managing Microsoft, Unix, Linux, and Novell servers for a network with more than 3,500 users. He has developed online programming and Linux courses that he teaches to students worldwide.
Read more about Richard Blum

Christine Bresnahan
Christine Bresnahan
author image
Christine Bresnahan

Christine Bresnahan has worked in the IT industry for more than 30 years and is currently an adjunct professor of Python programming and Linux system administration classes at Ivy Tech Community College in Indianapolis. She is the co-author of Linux Bible, Eighth Edition, and Linux Command Line and Shell Scripting Bible.
Read more about Christine Bresnahan

View More author details
Right arrow

The for Command

Iterating through a series of commands is a common programming practice. Often, you need to repeat a set of commands until a specific condition has been met, such as processing all the files in a directory, all the users on a system, or all the lines in a text file.

The bash shell provides the for command to allow you to create a loop that iterates through a series of values. Each iteration performs a defined set of commands using one of the values in the series. Here's the basic format of the bash shell for command:

 for var in list
 do
    commands
 done

You supply the series of values used in the iterations in the list parameter. You can specify the values in the list in several ways.

In each iteration, the variable var contains the current value in the list. The first iteration uses the first item in the list, the second iteration the second item, and so on until all the items in the list have been used.

The commands entered between the do and done statements...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Linux Command Line and Shell Scripting Bible - Third Edition
Published in: Jan 2015Publisher: WileyISBN-13: 9781118983843

Authors (2)

author image
Richard Blum

Richard Blum has more than 25 years as a network and systems administrator, currently managing Microsoft, Unix, Linux, and Novell servers for a network with more than 3,500 users. He has developed online programming and Linux courses that he teaches to students worldwide.
Read more about Richard Blum

author image
Christine Bresnahan

Christine Bresnahan has worked in the IT industry for more than 30 years and is currently an adjunct professor of Python programming and Linux system administration classes at Ivy Tech Community College in Indianapolis. She is the co-author of Linux Bible, Eighth Edition, and Linux Command Line and Shell Scripting Bible.
Read more about Christine Bresnahan