CHAPTER 3Looping and Branching
At the heart of any programming language are iteration and conditional execution. Iteration is the repetition of a section of code until a condition changes. Conditional execution is making a choice between two or more actions (one of which may be to do nothing) based on a condition.
In the shell, there are three types of loop (while, until
, and for
) and three types of conditional execution (if, case
, and the conditional operators &&
and ||
, which mean AND
and OR
, respectively). With the exception of for
and case
, the exit status of a command controls the behavior.
Exit Status
You can test the success of a command directly using the shell keywords while, until
, and if
or with the control operators &&
and ||
. The ...
Get Pro Bash Programming: Scripting the GNU/Linux Shell 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.