Bash Scripting Sunday #1: Bash Parameter Expansion - Save Time and Avoid Subshells

In this entry, I’d like to show you how to use Bash Parameter Expansion to make your life a little easier, your scripts a little quicker, and use less resources.

Here’s an example script that isn’t using Bash Parameter Expansion:

#!/usr/bin/env bash
filename="/path/to/file.txt"
echo "Basename: $(basename $filename)"      # file.txt
echo "Dirname: $(dirname $filename)"        # /path/to

This script will output: