Parameter manipulation

Perhaps a little more useful to us in scripting is the C-style parameter manipulation that we can include using the double parenthesis. We can often use this to increment a counter within a loop and also put a limit on the number of times the loop iterates. Consider the following command:

$ COUNT=1$ (( COUNT++ ))echo $COUNT

Within this example, we first set COUNT to 1 and then we increment it with the ++ operator. When it is echoed in the final line, the parameter will have a value of 2. We can see the results in the following screenshot:

We can achieve the same result in longhand by using the following syntax:

$ COUNT=1 ...

Get Mastering Linux Shell Scripting 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.