Preface

The shell on a GNU/Linux system is arguably the most powerful tool for any user. In general terms, the shell serves as an interface between the system's user and the operating system kernel. We use the shell to run commands in order to perform tasks and frequently save the output to files. While these simple use-case are easy to achieve by just using some commands on the shell, sometimes the task at hand is more complex than that.

Enter shell scripting, the magical tool that allows you to write step-by-step instructions to the shell on how to perform a complex task. However, just learning the syntax to write scripts is not enough unless you know the commands at your disposal. Only then would scripts be reusable, efficient, and easy to use. When one has mastered the commands available on a GNU/Linux system, what follows is a frenzy to automate daily tasks—be it finding documents or cleaning up old movies that have long been watched. Whether you're an expert with other scripting languages or you're doing this for the first time, this book will show you how to do magic with shell scripts!

What this book covers

Chapter 1, The Beginning of the Scripting Journey, tells you about the importance of writing shell scripts along with a simple Hello World shell script program. It also covers the basic and essential shell script topics such as defining a variable, built-in variables, and operators. It also contains a detailed explanation of shell expansion that occurs with characters such as ~, *, ?, [], and {}.

Chapter 2, Getting Hands-on with I/O, Redirection Pipes, and Filters, talks about the standard input, output, and error streams for a command and shell script. It also has instructions on how to redirect them to other streams. One of the most powerful concepts, namely regular expressions, is also covered. It serves as instructions to commands such as grep, sed, uniq, and tail for filtering useful data from input data.

Chapter 3, Effective Script Writing, provides an insight into structuring shell scripts to organize tasks. After talking about script exit codes, it talks about basic programming constructs such as conditionals and loops. It then goes on to discuss the organization of code into functions and aliases. Finally, it wraps up with details on how xargs, pushd, and popd works.

Chapter 4, Modularizing and Debugging, talks about making shell scripts modular by using common code that can be sourced. It also covers the details of command line arguments to scripts and how one can debug their scripts when they malfunction. This chapter also contains information on how the user can implement custom command completion.

Chapter 5, Customizing the Environment, moves on to talk about the shell environment - what it contains, its significance, and finally how to modify it. It also takes the reader through the different initialization files that bash uses at startup. Finally, we talk about how to check command history and manage running tasks.

Chapter 6, Working with Files, talks about files, which are the entities that most of any UNIX system is composed of. It covers the basic philosophy of "everything is a file" and takes the reader through basic file operations, comparing files, finding them, and creating links. This chapter then explains what special files and temporary files are, and the details involved in file permissions.

Chapter 7, Welcome to the Processes, talks about executable files that come alive—and become processes. From listing and monitoring running processes, it goes on to talk about how to exploit process substitution. Next, it covers process scheduling priorities, signals, traps, and how processes can communicate with each other.

Chapter 8, Scheduling Tasks and Embedding Languages in Scripts, discusses scheduling tasks at appropriate times by using the system Cron. Next, it covers systems that are responsible for orchestrating startup tasks in most modern Linux systems. Finally, this chapter contains instructions on how to embed scripts from other scripting languages into a shell script.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.51.233