Learn Bash the Hard Way
This bash course has been written to help bash users to get to a deeper understanding and proficiency in bash. It doesn’t aim to make you an expert immediately, but you will be more confident about using bash for more tasks than just one-off commands.
Introduction
Why Learn Bash?
There are a few reasons to learn bash in a structured way:
- Bash is ubiquitous
- Bash is powerful
You often use bash without realising it, and people often get confused by why it sometimes doesn’t work as you expect it to, or even why bash works after they’re given one-liners to run.
It doesn’t take long to get a better understanding of bash, and once you have the basics, its power and ubiquity mean that you can be useful in all sorts of contexts.
Why Learn Bash The ‘Hard Way’?
The ‘Hard Way’ is a method that emphasises the process required to learn anything. You don’t learn to ride a bike by reading about it, and you don’t learn to cook by reading recipes. Books can help (this one hopefully does) but it’s up to you to do the work.
This book shows you the path in small digestible pieces based on my decades of experience and tells you to actually type out the code. This is as important as riding a bike is to learning to ride a bike. Without the brain and the body working together, the knowledge does not get there.
If you follow this course, you will get an understanding of bash that can form the basis of mastery as you use it in the future.
What You Will Get
This course aims to give students:
- A hands-on, quick and practical understanding of bash
- Enough information to understand what is going on as they go deeper into bash
- A familiarity with advanced bash usage
It does not:
- Give you a mastery of all the tools you might use on the command line, eg sed, awk, perl
- Give a complete theoretical understanding of all the subtleties and underpinning technologies of bash
- Explain everything. Plenty of time to go deeper and get all the nuances later if you need them
You are going to have to think sometimes to understand what is happening. This is the Hard Way, and it’s the only way to really learn. This course will save you time as you scratch your head later wondering what something means, or why that StackOverflow answer worked.
Sometimes the course will go into other areas closely associated with bash, but not directly bash-related, eg specific tools, terminal knowledge. Again, this is always oriented around my decades of experience using bash and other shells.
Assumptions
It assumes some familiarity with very basic shell usage and commands. For those looking to get to that point, I recommend following this set of mini-tutorials:
It also assumes you are equipped with a bash shell and a terminal. If you’re unsure whether you’re in bash, type:
echo $BASH_VERSION
into your terminal. If you get a bash version string output like this then you are in bash:
3.2.57(1)-release
How The Course Works
The course demands that you type out all the exercises to follow it.
Frequently, the output will not be shown in the text, or even described.
Any explanatory text will assume you typed it out. Again, this is the Hard Way, and we use it because it works.
This is really important: you must get used to working in bash, and figuring out what’s going on by scratching your head and trying to work it out before I explain it to you. Eventually you will be on our own out there and will need to think for yourself. I’m trying to prepare you for that day.
Each section is self-contained, and must be followed in full. To help show you where you are, the shell command lines are numbered 1-n and the number is followed by a $
sign, eg:
1 $ first command2 $ second command
At the end of each section is a set of ‘cleanup’ commands (where needed) if you want to use them to leave no trace of your work.
Structure
This book is structured into four parts:
Part I - Core Bash
Core foundational concepts essential for understanding bash on the command line.
Part II - Scripting Bash
Gets your bash scripting skills up to a proficient point.
Part III - Tips
A primer on commonly-used techniques and features that are useful to know about.
Part IV - Advanced Bash
Building on the first three chapters, and introducing some more advanced features, this chapter takes your bash skills beyond the norm.