Book Image

Bash Quick Start Guide

By : Tom Ryder
Book Image

Bash Quick Start Guide

By: Tom Ryder

Overview of this book

Bash and shell script programming is central to using Linux, but it has many peculiar properties that are hard to understand and unfamiliar to many programmers, with a lot of misleading and even risky information online. Bash Quick Start Guide tackles these problems head on, and shows you the best practices of shell script programming. This book teaches effective shell script programming with Bash, and is ideal for people who may have used its command line but never really learned it in depth. This book will show you how even simple programming constructs in the shell can speed up and automate any kind of daily command-line work. For people who need to use the command line regularly in their daily work, this book provides practical advice for using the command-line shell beyond merely typing or copy-pasting commands into the shell. Readers will learn techniques suitable for automating processes and controlling processes, on both servers and workstations, whether for single command lines or long and complex scripts. The book even includes information on configuring your own shell environment to suit your workflow, and provides a running start for interpreting Bash scripts written by others.
Table of Contents (10 chapters)

Redirecting input

Many commands invoked from Bash read their input from one or more files provided on the command line, particularly the classic Unix text filtering tools, such as grep and sort. When these commands are passed one or more filenames as arguments, they switch to reading their input from those files in the order they were specified, instead of from their own standard input:

$ grep pattern myfile1 myfile2 myfile3
$ sort -k1,1 myfile1 myfile2 myfile3

This tends to mean that you do not need to use Bash to redirect input as often as you need to redirect output, because well-designed Unix programs can usually change their input behavior by specifying filenames, without any shell syntax involved.

However, not all programs behave this way, and it will sometimes be necessary to use input redirection to specify the source for a command's input. For example, the tr Unix...