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 ...

Get SAMS Teach Yourself Unix in 10 Minutes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.