Shorthand syntax

By now, we've seen a few uses of an if block to see if our previous commands ran successfully. While the functionality is great, using 5-7 lines after each command where you suspect errors could occur really adds to the total script length! Even more of an issue will be readability: if half the script is error checking, it might be very hard to get to the bottom of the code. Fortunately, there is a way in which we can check for errors directly after a command. We can accomplish this with the || command, which is the Bash version of a logical OR. Its counterpart, &&, is the implementation of a logical AND. To illustrate this, we'll introduce two new commands: true and false. If you take a look at the respective man pages, ...

Get Learn Linux Shell Scripting - Fundamentals of Bash 4.4 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.