ABSTRACT

In this chapter, we will cover one of the most useful tools for the implementation and automation of complex tasks in Unix-based systems: Bash scripting. Bash is one of the most common (if not the most common) shells used in these systems, particularly in Linux. As do all shells, Bash serves as an interface between the user and the kernel, and as such, it provides a language for handling system-level objects (such as jobs, processes, and files) with ease. Bash implements a “read-evaluate-print loop” (REPL) environment, which reads user input, evaluates it, and prints the result. This type of environment enables rapid development and debugging, compared to classical compiled languages. Even though there are scripting languages that are easier to learn and have a large code base in the form of libraries (such as Python), Bash is often used to write “master scripts” to combine code from different sources and manage files and processes, as those tasks are much easier to implement in Bash. Bash scripts are also highly portable, as nearly every Unix-like system will include the Bash shell. More details beyond what is covered in this chapter can be found in the references at the end of the chapter [1,2]. The examples in this chapter were tested with GNU Bash version 3.2.48 (the version of Bash running in a system can be found by running bash —version).