From bb88623af1d06a25f5996120d5977a2881deec4d Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 19 Sep 2019 21:00:15 +0300 Subject: [PATCH] docs: update --- README.md | 10 ++++++---- manuscript/chapter5.txt | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) 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:-/}" } ```