O'Reilly logo

SAMS Teach Yourself Unix in 10 Minutes by Robert Shimonski

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using foreach

When you find yourself putting in commands over and over, you can use the foreach statement that executes a code block for each data item in an array. An array is a set of elements indexed sequentially that have the same type of data. Most times, each element of an array has a unique identifying index number. Changes made to one element of an array do not affect the other elements. foreach specifies that for each entry in the array of entries, Unix will output the entries to the terminal. Commonly, foreach is used in place of a standard for loop. Unlike this for loop construct, however, a foreach loop usually does not specify the order in which the items are considered.

The point of this is, if you don't want to spend a massive ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required