Book Image

Mastering Linux Shell Scripting

By : Andrew Mallett
Book Image

Mastering Linux Shell Scripting

By: Andrew Mallett

Overview of this book

Shell scripting is a quick method to prototype a complex application or a problem by automating tasks when working on Linux-based systems. Using both simple one-line commands and command sequences complex problems can be solved with ease, from text processing to backing up sysadmin tools. In this book, you’ll discover everything you need to know to master shell scripting and make informed choices about the elements you employ. Get to grips with the fundamentals of creating and running a script in normal mode, and in debug mode. Learn about various conditional statements' code snippets, and realize the power of repetition and loops in your shell script. Implement functions and edit files using the Stream Editor, script in Perl, program in Python – as well as complete coverage of other scripting languages to ensure you can choose the best tool for your project.
Table of Contents (21 chapters)
Mastering Linux Shell Scripting
About the Author
About the Reviewer


We have begun to make progress within this chapter. We have been able to join many of the elements that we have previously used into cohesive and functional scripts. Although the focus of this chapter has been on loops, we have used command-line lists, if statements, case statements, and arithmetic calculations.

We opened this chapter describing loops as the workhorse of our scripts and we have been able to demonstrate this with for, while, and until loops. The for loop is used to iterate through elements of a list. The list can be either static or dynamic, with an emphasis on dynamic lists we showed how simply these are created via file globbing or command expansion.

The while and until loops are controlled using conditions. The while loop will loop whilst the supplied condition is true. The until loop will loop until the supplied condition returns true or whilst it returns false. The continue and break keywords are specific to loops and along with exit, we can control the loop flow...