Bash Scripting in 3 Weeks
Published by O'Reilly Media, Inc.
From beginner to professional, robust shell scripter
Shell scripts have been around for 50 years, and Bash for over 30 years. As other technologies have come and gone, Bash scripting is still used daily by millions of engineers across the world, and shows no sign of going away. Despite its obscure syntax, which can be baffling to newcomers, its power as a tool for getting things done means it is still essential to learn if you have ambitions of becoming a senior engineer. Experienced engineers are assumed to have the ability to script in Bash, but there is little explicit support for newcomers to gain this fundamental skill.
Join Linux expert Ian Miell to get up to speed on Bash scripting and the tools and techniques you’ll need to write professional Bash code. The course will be helpful for students who want to earn Linux Foundation LFCS, CompTIA Linux+, or Red Hat RHCSA certifications.
Week 1: Your First Bash Scripts
In Week 1, you’ll create your first Bash script and learn about the central constructs of Bash as a programming language. In addition, you’ll cover the most common commands (such as grep, chmod, find, read) and how they are best used in shell scripts.
Week 2: Scripting Techniques
In Week 2, you’ll build on earlier work by learning about more advanced shell scripting techniques such as pipes and redirection, subshells, file handles, and command substitution. You’ll also cover more commonly used shell scripting commands, such as xargs, wc, uniq, sed, and rsync. With these commands at your fingertips, you’ll be able to tackle the vast majority of everyday challenges that can be solved by shell scripts and to read and critique most shell scripts already in use.
Week 3: Advanced Scripting
Week 3, you’ll focus on writing robust, sophisticated, and professional shell scripts that will mark you as a senior engineer. You’ll learn about job control, signal trapping, and how to debug scripts when they go wrong. You’ll also learn about the most important system commands that you might use in your scripts or for general debugging.
NOTE: With today’s registration, you’ll be signed up for all three sessions. Although you can attend any of the sessions individually, we recommend participating in all three weeks and pursuing the skills challenges in between sessions.
Skills challenges
At the end of each week, Ian Miell will provide you with a skills challenge—an interactive scenario-based evaluation to help you determine whether you’ve mastered the skills taught in the live training and whether you’re ready to apply these skills in a real-world setting.
To reinforce your learning, we strongly recommend pursuing each skills challenge before the next week of the course. If you’re unable to successfully complete the challenge, try reviewing the video recording of the live training (emailed to you 24 hours after each session) for tips.
What you’ll learn and how you can apply it
By the end of this live, hands-on three-part series, you’ll understand:
Week 1: Your First Bash Scripts
- What shell scripts are and why they are important
- The core elements of shell scripts and how to write them
- The core commands you may use in shell scripts
Week 2: Scripting Techniques
- Pipes and redirection
- Common file commands
- Subshells
- Common Bash scripting gotchas
Week 3: Advanced Scripting
- How to trap signals
- How to debug Bash scripts
- How to lint Bash scripts
- Bash job management
- System management commands
And you’ll be able to:
Week 1: Your First Bash Scripts
- Set up and write a basic shell script
- Use common commands with ease
Week 2: Scripting Techniques
- Write a script that does useful work
- Write cleaner, more professional-looking Bash code
Week 3: Advanced Scripting
- Understand and debug any script that is thrown at you
- Write a script that is ready for production
This live event is for you because...
- You’re a software engineer.
- You work with Linux.
- You want to become a senior software engineer.
Prerequisites
- Access to Linux terminal
- Basic understanding of software development and programming
Recommended preparation:
- Watch “Writing Your First Scripts” (video segment)
- Watch “Why Scripting in Bash Makes Sense” (video segment)
- Watch “Making Decisions in Bash” (video segment)
Recommended follow-up:
- Read bash Idioms (book)
- Read bash Cookbook, second edition (book)
- Review Command Line Essentials (expert playlist)
Schedule
The time frames are only estimates and may vary according to how the class is progressing.
Week 1: Your First Bash Scripts
Introduction to the shell (60 minutes)
- Presentation: Introduction and overview; your first shell script
- Group discussion: Your level of experience; What do you want from the course?
- Q&A
- Hands-on exercise: Create your first shell script
- Break
Basic programming in the shell (80 minutes)
- Group discussion: Review previous exercise; Is the shell a programming language?
- Presentation: Shell variables; loops; GNU Core commands—files and folders
- Break
- Hands-on exercise: Create 100 files in a shell script
- Q&A
Tests and command substitution (55 minutes)
- Group discussion: Review previous exercise
- Presentation: Tests and exit codes; command substitution
- Hands-on exercise: Quit the script when you find the 50th file
- Q&A
- Break
Shell functions (45 minutes)
- Presentation: Functions; GNU Core commands—grep, find, and wc
- Skills challenge: List the files in your home folder and below, and the number of lines each file has
- Q&A
Week 2: Scripting Techniques
Pipes, redirects, and file handles (60 minutes)
- Group discussion: Review last week’s skills challenge
- Presentation: Pipes, redirects, and file handles
- Q&A
- Hands-on exercise: A script that logs intelligently
- Break
Process substitution and subshells (60 minutes)
- Group discussion: Review previous exercise
- Presentation: Process substitution; subshells
- Q&A
- Hands-on exercise: Adapt previous scripts to use process substitution and subshells
- Break
Globs, regexps, and heredocs (60 minutes)
- Group discussion: Review previous exercise
- Presentation: Globs and regexps; heredocs
- Hands-on exercise: Create files inline in a script, and then report on lines that match
- Q&A
- Break
Shell startup (60 minutes)
- Group discussion: Review previous exercise
- Presentation: Sourcing and Startup; GNU Core commands—tee, uname, id, date, wc
- Q&A
- Skills challenge: A sophisticated file reporting tool
Week 3: Advanced Scripting
Debugging the shell (60 minutes)
- Group discussion: Review last week’s skills challenge
- Presentation: Debugging your scripts
- Q&A
- Hands-on exercise: Take a broken script, find the problems, and fix them
- Break
Job management (60 minutes)
- Group discussion: Review previous exercise
- Presentation: Job management
- Q&A
- Hands-on exercise: Spin up multiple file reporters, gather the output and re-present it
- Break
Signal traps (60 minutes)
- Group discussion: Review previous exercise
- Presentation: Signal traps; advanced commands—ip, nc, dig, strace, systemctl, lsof
- Q&A
- Hands-on exercise: Write a program that is difficult to exit
- Break
IFS and more tests (50 minutes)
- Group discussion: Review previous exercise
- Presentation: IFS; more on tests—unary and binary operators
Wrap-up and Q&A (10 minutes)
Your Instructor
Ian Miell
Ian Miell has over twenty years' experience in IT, writing, running, architecting, and maintaining software for some of the world's busiest systems.
He has written the book 'Docker in Practice' (published by Manning), 'Learn Bash the Hard Way' (published on Leanpub), as well as various training courses and videos.