
Member-only story
Quick Tut: Shell Scripting Tricks
Understand those secret shell script tricks with this quick and easy tutorial.
I’m sure you’ve seen some strange stuff when looking at shell scripts. This tutorial is a just a quick overview of some those secret tricks that are hard to figure out what they are with just a Google search. I primarily use the BASH, ZSH and ASH shells, so these are things that I believe work with those; I won’t specifiy whether these things work in other shells or whether they are POSIX.
If you’re writing things like Docker entrypoint.sh scripts (which is what I’ve been doing a lot of lately), these knowing this stuff will really come in handy.
Here is some basic shell terminology you need to know.
- Parameter: A parameter is essentially just a variable, except BASH distinguishes between Positional Parameters, the parameters supplied to the script on the command line, like:
./my_script.sh these are positional parameters
- and Variable Parameters, the parameters defined inside the script, like:
my_variable_parameter=’hello’;
- Word: A word is just a string.
- Pattern: A regex matching pattern.
What This Tutorial Covers
- Tests
- Redirection & Piping
- Parameter & Other Expansions
- Subshells
- The Set Command
- Special Variables
What You Need For This Tutorial
- A terminal if you want to play around with these tricks.

Tests
By tests, I’m just referring to how ‘if’ evaluates expressions. The way shell scripts…