Book Image

Linux Shell Scripting Bootcamp

By : James K Lewis
Book Image

Linux Shell Scripting Bootcamp

By: James K Lewis

Overview of this book

Linux Shell Scripting Bootcamp is all about learning the essentials of script creation, validating parameters, and checking for the existence of files and other items needed by the script. We will use scripts to explore iterative operations using loops and learn different types of loop statements, with their differences. Along with this, we will also create a numbered backup script for backup files. Further, you will get well-versed with how variables work on a Linux system and how they relate to scripts. You’ll also learn how to create and call subroutines in a script and create interactive scripts. The most important archive commands, zip and tar, are also discussed for performing backups. Later, you will dive deeper by understanding the use of wget and curl scripts and the use of checksum and file encryption in further chapters. Finally, you will learn how to debug scripts and scripting best practices that will enable you to write a great code every time! By the end of the book, you will be able to write shell scripts that can dig data from the web and process it efficiently.
Table of Contents (19 chapters)
Linux Shell Scripting Bootcamp
About the Author
About the Reviewer
Customer Feedback

Syntax errors

Nothing can be so frustrating than to be on a roll when coding your script or program and then have a syntax error pop up. In some cases the solution is so easy you find and solve it right away. In other cases it can take minutes or even hours. Here are a few pointers:

When coding a loop put the whole structure in first. It is sometimes really easy to forget the ending done statement, especially if the code spans more than a page.

Take a look at Script 1:

Chapter 9 - Script 1

# 6/7/2017
echo "Chapter 9 - Script 1"

while [ $x -lt 5 ]
 echo "x: $x"
 let x++

while [ $y -lt 5 ]
 echo "y: $y"
 let y++

# more code here
# more code here

echo "End of script1"
exit 0

And here is the output:

Look at this real closely, it says the error is at line 26. Wow, how can that be, when the file has only has 25 lines in it? The simple answer is that's just the way the Bash interpreter handles this type of situation. If you have not already found...