O'Reilly logo

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

Linux Shell Scripting Bootcamp

Book Description

A quick and straightforward approach to writing shell scripts to accomplish different types of tasks on a Linux system.

About This Book

  • Understand expressions and variables and how to use them practically
  • Familiarize yourself with the various text filtering tools available in Linux
  • A fast-paced and concise guide that gets you well versed with linux shell scripting.

Who This Book Is For

This book is for both GNU/Linux users who want to do amazing things with the shell and for advanced users looking for ways to make their lives with the shell more productive.

What You Will Learn

  • Get acquainted with the basics of a shell script to serve as a refresher for more advanced topics
  • Learn different ways to create and run a script
  • Discuss the passing and verification of parameters, along with the verification of other items.
  • Understand the different forms of conditions and loops, and go over the sleep command in detail
  • Learn about different ways to handle the reporting of return codes
  • Create an interactive script by reading the keyboard and use subroutines and interrupts
  • Create scripts to perform backups and go over the use of encryption tools and checksums
  • Use wget and curl in scripts to get data directly from the Internet

In Detail

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.

Style and approach

This book is all about fast and intensive learning. This means we don’t waste time in helping readers get started. The new content is basically about filling in with highly-effective examples to build new things, solving problems in newer and unseen ways, and solving real-world examples.

Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the code file.

Table of Contents

  1. Linux Shell Scripting Bootcamp
    1. Table of Contents
    2. Linux Shell Scripting Bootcamp
    3. Credits
    4. About the Author
    5. Acknowledgement
    6. About the Reviewer
    7. www.PacktPub.com
      1. eBooks, discount offers, and more
        1. Why subscribe?
    8. Customer Feedback
    9. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    10. 1. Getting Started with Shell Scripting
      1. Getting started
        1. Using a good text editor
      2. Demonstrating the use of scripts
        1. Chapter 1 - Script 1
        2. Chapter 1 - Script 2
        3. Chapter 1 - Script 3
        4. Chapter 1 - Script 4
        5. Chapter 1 - Script 5
        6. Chapter 1 - Script 6
      3. Summary
    11. 2. Working with Variables
      1. Using variables in scripts
        1. Chapter 2 - Script 1
      2. Validating parameters using conditional statements
        1. Chapter 2 - Script 2
      3. Comparison operators for strings
        1. Chapter 2 - Script 3
        2. Chapter 2 - Script 4
        3. Chapter 2 - Script 5
      4. Environment variables
        1. Chapter 2 - Script 6
        2. Chapter 2 - Script 7
      5. Summary
    12. 3. Using Loops and the sleep Command
      1. Using loops
        1. Chapter 3 - Script 1
        2. Chapter 3 - Script 2
        3. Chapter 3 - Script 3
      2. Screen manipulation
        1. Chapter 3 - Script 4
        2. Chapter 3 - Script 5
      3. Indenting your code
        1. Chapter 3 - Script 6
      4. Using the for statement
        1. Chapter 3 - Script 7
        2. Chapter 3 - Script 8
      5. Leaving a loop early
        1. Chapter 3 - Script 9
      6. The sleep command
        1. Chapter 3 - Script 10
        2. Chapter 3 - Script 11
      7. Watching a process
        1. Chapter 3 - Script 12
      8. Creating numbered backup files
        1. Chapter 3 – Script 13
      9. Summary
    13. 4. Creating and Calling Subroutines
      1. Clearing the screen
        1. Chapter 4 - Script 1
      2. File redirection
      3. Command piping
        1. Chapter 4 - Script 2
        2. Chapter 4 - Script 3
      4. Subroutines
        1. Chapter 4 - Script 4
      5. Using parameters
        1. Chapter 4 - Script 5
        2. Chapter 4 - Script 6
      6. Making a current backup of your work
        1. Chapter 4 – Script 7
      7. Summary
    14. 5. Creating Interactive Scripts
      1. Chapter 5 - Script 1
        1. Chapter 5 - Script 2
        2. Chapter 5 - Script 3
        3. Chapter 5 - Script 4
        4. Chapter 5 - Script 5
        5. Chapter 5 - Script 6
        6. Chapter 5 - Script 7
        7. Chapter 5 - Script 8
      2. Summary
    15. 6. Automating Tasks with Scripts
      1. Chapter 6 - Script 1
        1. Chapter 6 - Script 2
        2. Chapter 6 - Script 3
        3. Chapter 6 - Script 4
        4. Cron
        5. Chapter 6 - Script 5
        6. Chapter 6 - Script 6
        7. Chapter 6 - Script 7
      2. Summary
    16. 7. Working with Files
      1. Writing files
        1. Chapter 7 - Script 1
      2. Reading files
        1. Chapter 7 - Script 2
        2. Chapter 7 - Script 3
        3. Chapter 7 - Script 4
      3. Reading and writing files
        1. Chapter 7 - Script 5
      4. Reading and writing files interactively
        1. Chapter 7 - Script 6
      5. File checksums
      6. File encryption
        1. Chapter 7 - Script 7
      7. Summary
    17. 8. Working with wget and curl
      1. Introducing the wget program
        1. wget options
        2. wget return codes
        3. wget configuration files
          1. Chapter 8 - Script 1
      2. wget and recursion
      3. wget options
      4. curl
        1. curl options
          1. Chapter 8 - Script 2
      5. Summary
    18. 9. Debugging Scripts
      1. Syntax errors
        1. Chapter 9 - Script 1
        2. Chapter 9 - Script 2
      2. Automatic backups
      3. More syntax errors
        1. Chapter 9 - Script 3
      4. Logic errors
        1. Chapter 9 - Script 4
      5. Using set to debug scripts
        1. Chapter 9 - Script 5 and Script 6
        2. Chapter 9 - Script 7
        3. Chapter 9 - Script 8
        4. Chapter 9 - Script 9
      6. Summary
    19. 10. Scripting Best Practices
      1. Verifying backups
      2. ssh and scp
      3. Find and use a good text editor
      4. Environment variables and aliases
      5. ssh prompt
      6. Testing an archive
      7. Progress indicator
        1. Chapter 10 - Script 1
      8. Creating new commands from a template
        1. Chapter 10 – Script 2
      9. Alerting the user
          1. Chapter 10 – Script 3
      10. Summary
    20. Index