O'Reilly logo

LPIC-1/CompTIA Linux+™ Certification All-in-One Exam Guide by Robb Tracy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Control Structures in Scripts

In addition to interactivity, it can also be very beneficial to add control structures to your shell scripts. Our scripts, to this point, have executed straight through from beginning to end. This works fine, but what if we need the script to make some decisions? Based on user input or output from a command, you may want the script to determine a course of action. This is done by implementing control structures in the script. We’re going to discuss the following about this type of script element:

• Using if/then/else structures

• Using case structures

• Using looping structures

Let’s begin by reviewing if/then statements.

Using if/then Structures

Using an if/then/else structure within your shell script gives ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required