
- 186 pages
- English
- ePUB (mobile friendly)
- Available on iOS & Android
About this book
Learn how to write shell script effectively with Bash, to quickly and easily write powerful scripts to manage processes, automate tasks, and to redirect and filter program input and output in useful and novel ways.
Key Features
- Demystify the Bash command line
- Write shell scripts safely and effectively
- Speed up and automate your daily work
Book Description
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.
What you will learn
- Understand where the Bash shell fits in the system administration and programming worlds
- Use the interactive Bash command line effectively
- Get to grips with the structure of a Bash command line
- Master pattern-matching and transforming text with Bash
- Filter and redirect program input and output
- Write shell scripts safely and effectively
Who this book is for
People who use the command line on Unix and Linux servers already, but don't write primarily in Bash. This book is ideal for people who've been using a scripting language such as Python, JavaScript or PHP, and would like to understand and use Bash more effectively.
Tools to learn more effectively

Saving Books

Keyword Search

Annotating Text

Listen to it instead
Information
Essential Commands
Distinguishing command types
- Shell builtin commands: Included in Bash itself. These commands don't correspond to executable program files on your system; they are implemented in the bash binary itself. Examples are echo, type, and source.
- Runtime commands: Defined in the shell at runtime, and written in the Bash language. These can be aliases or functions. They don't have executable program files of their own on disk either, and are defined at runtime during a Bash session, often by reading startup files. Examples vary between systems and users.
- System commands: Invoke executable program files on your filesystem. These are the only kinds of commands that can also be run outside of Bash. Examples are grep, ping, and rm.
- type: Finding what a command is
- echo: Printing arguments
- printf: Printing formatted arguments
- pwd: Printing the current directory
- cd: Changing the current directory
- set: Viewing and setting shell properties
- declare: Managing variables and functions
- test, [, [[: Evaluating expressions
- ls: Listing files for users
- mv: Moving and renaming files
- cp: Copying files
- rm and rmdir: Deleting files and directories
- grep: Matching patterns
- cut: Extracting columns from data
- wc: Counting lines, words, and characters
- find: Iterating through a file tree
- sort and uniq: Sorting and de-duplicating input
Essential Bash builtin commands
bash$ help type
The type command
bash$ type echo echo is a shell builtin bash$ type grep grep is /bin/grep
bash$ type for for is a shell keyword
bash$ myfunc() { : ; } bash$ type myfunc myfunc is a function
myfunc ()
{
:
}
bash$ alias myalias=: bash$ type myalias myalias is aliased to `:' bash$ type -t echo builtin bash$ type -t grep file
bash$ type -a true true is a shell builtin true is /bin/true
$ /bin/true
bash$ type -P true /bin/true
The echo command
$ echo Hello Hello
$ echo 'Hello, '"$USER"\! Hello, bashuser!
The printf command
$ printf '%s\n' 'Hello!' Hello!
$ printf '%s\n' -n -n $ string=-n $ printf '%s\n' "$string" -n
$ printf '%s\n' foo bar baz foo bar baz
bash$ printf '%q\n' 'Watch out for thi$ $tring; it \has\ nasty character$!' Watch\ out\ for\ thi\$\ \$tring\;\ it\ \\has\\\ nasty\ character\$\!
The pwd command
Table of contents
- Title Page
- Copyright and Credits
- Dedication
- Packt Upsell
- Contributors
- Preface
- What is Bash?
- Bash Command Structure
- Essential Commands
- Input, Output, and Redirection
- Variables and Patterns
- Loops and Conditionals
- Scripts, Functions, and Aliases
- Best Practices
- Other Books You May Enjoy
Frequently asked questions
- Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
- Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app