A shell script is a computer program designed to be run by the Unix shell, a command line interpreter. It is a text file containing a sequence of shell commands and constructs that perform a routine task. This sequence is typically executed by entering the name of the script on the command line. Alternatively, a script can be initialised using cron, a time-based job scheduler. It makes little sense to continually type a sequence of commands at a command prompt, particularly if they are long, complex, or difficult to remember. Scripting offers the virtue of alleviating this unnecessary burden.

A shell is a user interface for access to an operating system’s services. It translates command lines typed at a terminal into system actions. The shell has built-in functions, which it performs directly, but most commands execute external programs. Linux has a wide range of text shells, such as Bash (Bourne Again SHell), Korn shell, C shell, tcsh, zsh, and the Bourne sh.

The main advantage of writing a shell script is that the commands and syntax are identical to typing them on the command line. In this way, the user does not have to learn a new language. Shell scripts enable lengthy and repetitive sequences of commands to be formed into a single, simple command. It enables new commands to be created, and enable external programs to be wrapped into an environment you can control. Shell scripts are often used in system administration, system boot scripts, application startup scripts, automation, package installation tools, and so much more.

A few of the books featured in this article are not specifically about shell scripting. However, they offer an excellent introduction to using the command line and are recommended for anyone wanting to fully exploit shell scripting.

The focus of this article is to select the finest shell scripting books which are available to download for free. Many of the books featured here can also be freely distributed. So get reading, learning and sharing.

By Mark Bates (HTML; 155 pages)

Conquering the Command Line offers the reader the opportunity to master and conquer the most valuable and useful command line tools for Unix and Linux based systems.

In this book the reader not only learns the most useful command line tools, but also the most helpful options and flags for those tools. Conquering the Command Line is not a rehash of the manual pages of each tool, but a human-readable walk-through of these tools to make you instantly more productive in your daily development life.

Chapters cover:

Basics and Navigation – provides a firm grasp on the basics of how to use the Unix (or Linux) command line

Ack/Ag – looks at two tools that can help make searching a large number of files fast and easy

cURL – a tool for working with URLs. cURL queries a URL from the command line

Find – looks at some of the most useful features of the find command

Grep – a tool for searching files for search terms, similar to ack or ag

Ps – looks at the most useful flags and options to use with ps

Sed – a stream editor that lets you quickly edit files or streams using pattern matching and replacements

Tar – quickly join together multiple files into one larger file, while still preserving meta-data such as Unix permissions

Extras – contains a few little extra commands

By Mendel Cooper (PDF, HTML; 945 pages)

Advanced Bash-Scripting Guide is an in-depth exploration of the art of scripting. Almost the complete set of commands, utilities, and tools is available for invocation by a shell script.

The book explains:

Basics such as special characters, quoting, exit and exit status

Beyond the Basics including loops and branches, command substitution, arithmetric expansion, recess time

Commands – Internal commands and builtins; External filters, programs and commands; System and Administrative Commands

Advanced topics: Regular Expressons, Here Documents, I/O Redirection, Subshells, Restricted Shells, Process Substitution, Functions, Aliases, List Constructs, Arrays, Indirect References, /dev and /proc, Of Zeros and Nulls, Debugging, Options, Gotchas, Scripting with Style

By Machtelt Garrels (PDF, HTML; 165 pages)

Everybody working on a UNIX or UNIX-like system who wants to make life easier on themselves, power users and sysadmins alike, can benefit from reading this book.

Explores:

Bash scripts

Writing and debugging scripts

The bash environment: Shell initialization files, Variables, Quoting characters, Shell expansion, aliases

Regular expressions

sed stream editor

awk programming language

Conditional statements (if, if/then/else, if/then/elif/else, Nested if statements, Boolean operations)

Writing interactive scripts

Repetitive tasks

Functions

Catching signals

By Steve Losh (HTML; 241 pages)

Learn Vimscript the Hard Way is a book for users of the Vim text editor who want to learn how to customize it.

Sections cover:

Basic Vim commands that you can use in your ~/.vimrc file to customize Vim quickly land easily

file to customize Vim quickly land easily Looks more deeply at Vimscript as a programming language, covering things like variables, conditionals, comparisons, functions, strings, string functions and more

Create a sample plugin intended for distribution to other Vim users. The plugin add support for the Potion programming language, a very small language

The source code to the book is available on BitBucket and on GitHub. To use this book you should have the latest version of Vim installed, which is version 7.3 at the time of this writing.

Next Section: 12 Remarkable Free Shell Scripting Books – Part 2

This article is divided into three parts:

Part 1, Part 2, Part 3

Return to our complete collection of recommended free and open source software including our latest additions.

Related articles