Shell scripting for humans
What you'll learn
- How to write shell scripts in bash
- How to use the command line
- How to use vim to create files
- How to parse and manipulate strings and text files
- How to use variables
- How to use conditionals to take action if something is true or false
- How to write loops to repeat a process
- How to understand logic and programming
- How to write a command line utility that accepts arguments and options
- A Mac (preferably) or other computer that can run a bash shell
This entire course is aimed at beginners, but if you're familiar with Linux or even other operating systems, you'll still get something out of the later sections in the course. At the end of the course, you'll have your own template script you can use to start creating your own.
You won't find any slides on this course; it's all hands-on work that lets you learn as you code. After the introduction, you'll start writing a script right away and I'll explain each line of code, what it does, and why you want it.
Throughout the course, you will write 20 different scripts:
first_script will print text to the screen (created with echo)
second_script will print text to the screen (created with `vim`) and uses a shebang
debug will run verbosely with extra output
debug2 will run verbosely with extra output (`vim` and `chmod` practice)
cd will move into a folder and list it's contents (a pseudo file browser script)
vars will assign and prints a variable
literal will assign and print a literal variable name
cmd_output_vars will save the output of a command in a variable and print it to the screen
if will do simple conditional checks
rename a broken script that will batch rename files using `if`/`else`/`mv` and more, bu quires you to fix it (debugging practice)
lowercase will use a for loop to loop through files in a directory
change_extension will change all files of a certain file extension to a new file extension
dir_args will accept a directory as an argument passed to it and list only folders it contains
version will print a version when the `--version` flag is passed (also practicing global and cal variable scopes)
usage will print a help message with `--help` or if no args are passed
logging will log to a file in three ways (INFO, WARN, DEBUG) using a log with the same name as the script
trap will show a message when you interrupt the script's execution
parse_args will parse for different arguments
detect_os will check several operating systems and display the one it detects
template will be a starting point you can use for all your future shell scripts
The start of the course is intentionally slow and broken into many small lectures. This allows you to really understand what's going on and let you absorb what you've learned and then apply it to a real-world example. In addition to learning shell scripting, you'll also learn about macOS and Linux in general as this helps you write better scripts.
I recommend using a Mac for this course because it has everything you need to get started without having to install anything extra. I'll also be working on a Mac throughout the course. But you'll be able to run all the same scripts from a Linux machine, or even a Windows machine that runs the Windows Subsystem for Linux. There will be some differences in those cases, but I'll explain them as we go.
If you're learning this for work, the first sections can get you up to speed quickly, while the later sections can help you uncover advanced topics you may need for your job.
If you're joining the course for your personal life, you can automate some tedious tasks you may do such as renaming files, data entry, finding things, etc.
Who this course is for:
- People interested in Linux or programming but don't know where to start
- People curious about programming that need an easy place to start
- People who have tried to learn programming but gave up
- People curious about Linux
- People curious about automation
- System admins or engineers
- Entry level programmers
I have a bachelor's degree in information technology. I have been writing bash scripts for ten years, and created several different open source command line utilities and projects, which you can find on GItHub.
I currently work in the high performance computing industry working exclusively with Linunx on a daily basis.
I remember when I first started working in Linux and feeling completely lost. I kept thinking it was easy to just click and point to do stuff. Writing cryptic commands on an old-looking terminal prompt seemed so bizarre. As I used it, I began to see the potential and how you could accomplish more on the command line than in a graphical interface.
The world of Linux, macOS, and the command line is filled with fun, nerdy things, which I'll show you along the way.
I'm not on social media but I do have GitHub and my personal blog, which is filled with all sorts of fun things I've done with scripting.