Book Image

Learn Linux Shell Scripting – Fundamentals of Bash 4.4

By : Sebastiaan Tammer
Book Image

Learn Linux Shell Scripting – Fundamentals of Bash 4.4

By: Sebastiaan Tammer

Overview of this book

Shell scripts allow us to program commands in chains and have the system execute them as a scripted event, just like batch files. This book will start with an overview of Linux and Bash shell scripting, and then quickly deep dive into helping you set up your local environment, before introducing you to tools that are used to write shell scripts. The next set of chapters will focus on helping you understand Linux under the hood and what Bash provides the user. Soon, you will have embarked on your journey along the command line. You will now begin writing actual scripts instead of commands, and will be introduced to practical applications for scripts. The final set of chapters will deep dive into the more advanced topics in shell scripting. These advanced topics will take you from simple scripts to reusable, valuable programs that exist in the real world. The final chapter will leave you with some handy tips and tricks and, as regards the most frequently used commands, a cheat sheet containing the most interesting flags and options will also be provided. After completing this book, you should feel confident about starting your own shell scripting projects, no matter how simple or complex the task previously seemed. We aim to teach you how to script and what to consider, to complement the clear-cut patterns that you can use in your daily scripting challenges.
Table of Contents (24 chapters)
Title Page
About Packt
Contributors
Preface
Free Chapter
1
Introduction
Index

Chapter 10


  1. What is a search pattern? A regular expression syntax which allows us to find pieces of text with specified characteristics, such as length, content and location on a line.
  2. Why are regular expressions considered greedy? Most regular expression try to find as much data as they can that match the search pattern. This includes whitespace and other punctuation, which is a logical separation for humans but not necessarily for a machine.
  3. Which character in search patterns is considered a wildcard for any one character, except newlines? The dot (.).
  4. How is the asterisk used in Linux regular expression search patterns? The * is used in combination with another character to allow it to form a repeating character. Example search pattern: spe*d will match spd, sped, speed, speeeeeeeeed, and so on.
  5. What are line anchors? The special characters used to denote line beginnings and endings. ^ for the beginning of the line, $ for the line end.
  6. Name three character types. Any of these are correct:
    • alphanumeric
    • alphabet
    • lowercase
    • uppercase
    • digits
    • blanks
  7. What is globbing? Globbing is accomplished when you use a * or ? on the command-line when interacting with files or file paths. Globbing allows us to easily manipulate (move, copy, delete, and so on) files that are matched on the globbing pattern.
  8. What is possible in the extended regular expression syntax, that is not possible with normal regular expressions under Bash?
    • One or more repeating characters
    • Exact number of repeating characters
    • Range of repeating characters
    • Alternation with more than a single character
  9. What would be a good rule of thumb between deciding to use grep or sed? If your goal can be achieved with a single grep statement, choose simplicity. If it cannot be achieved in that manner, choose sed for more powerful syntax.
  1. Why are regular expressions on Linux/Bash so hard? There are many different implementations that are similar. With regular expressions and their difficulty as-is, this confusion does not help. Only practice and experience will remedy this!