More conditions with elif
Moving onto where we require a greater degree of control, we can use the elif
keyword. Unlike else
, elif
requires an additional condition to be tested for each elif
. In this way, we can provide for different circumstances. We can add in as many elif
conditions as required. The following shows a pseudo-code:
if condition; then statement elif condition; then statement else statement fi exit 0
A script may make life easier for the operator by providing a simplified selection for a more complex code. Even though the script becomes gradually more complex to meet the requirements, to the operator the execution is greatly simplified. It is our job to enable users to run more complex operations easily from the command line when ...
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.