diff --git a/README.md b/README.md index d292e0c..8f98641 100644 --- a/README.md +++ b/README.md @@ -1101,11 +1101,13 @@ Alternative to the `basename` command. ```sh basename() { # Usage: basename "path" ["suffix"] - dir=${1%${1##*[!/]}} - dir=${dir##*/} - dir=${dir%"$2"} + local tmp - printf '%s\n' "${dir:-/}" + tmp=${1%${1##*[!/]}} + tmp=${tmp##*/} + tmp=${tmp%"${2/$1}"} + + printf '%s\n' "${tmp:-/}" } ``` diff --git a/manuscript/chapter5.txt b/manuscript/chapter5.txt index 41db729..bbf7514 100644 --- a/manuscript/chapter5.txt +++ b/manuscript/chapter5.txt @@ -40,11 +40,13 @@ Alternative to the `basename` command. ```sh basename() { # Usage: basename "path" ["suffix"] - dir=${1%${1##*[!/]}} - dir=${dir##*/} - dir=${dir%"$2"} + local tmp - printf '%s\n' "${dir:-/}" + tmp=${1%${1##*[!/]}} + tmp=${tmp##*/} + tmp=${tmp%"${2/$1}"} + + printf '%s\n' "${tmp:-/}" } ```