Parameter Expansion
${var##*/} strips everything up to and including the last / — a common way to get just a filename out of a full path. ${var%/*} does the reverse: it strips everything from the last / onward, leaving just the directory. ${var%.*} strips a file extension the same way.
script.sh
Try it yourself →path="/usr/local/bin/bash"
echo "${path##*/}"
echo "${path%/*}"
filename="archive.tar.gz"
echo "${filename%.*}"Output
bash /usr/local/bin archive.tar
${var:-default} expands to default only if var is unset or empty, without ever changing var itself — a concise way to supply a fallback without writing a whole if statement.
script.sh
Try it yourself →unset greeting
echo "${greeting:-Hello there}"
greeting="Hi"
echo "${greeting:-Hello there}"Output
Hello there Hi
Next: arithmetic — Bash's integer-only math, and the real error you get from dividing by zero.
Practice exercise
Given path="/var/log/app.log", extract just the filename without its extension ("app") using parameter expansion, and print it.