This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Description
As the second argument can be unbound in basename, the following script will fail:
#!/usr/bin/env bash
set -u
basename() {
# Usage: basename "path" ["suffix"]
local tmp
tmp=${1%"${1##*[!/]}"}
tmp=${tmp##*/}
tmp=${tmp%"${2/"$tmp"}"}
printf '%s\n' "${tmp:-/}"
}
basename ~/Pictures/Wallpapers/1.jpg
with
./basename.sh: line 11: 2: unbound variable