From 9d00d2413e34aa3b428772cc26c342e3890aae2c Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Thu, 19 Sep 2019 19:58:29 +0300 Subject: [PATCH] docs: update --- README.md | 10 ++++++++-- manuscript/chapter5.txt | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 88695a9..5569b9b 100644 --- a/README.md +++ b/README.md @@ -1101,8 +1101,11 @@ Alternative to the `basename` command. ```sh basename() { # Usage: basename "path" - : "${1%/}" - printf '%s\n' "${_##*/}" + dir=${1%${1##*[!/]}} + dir=${dir##*/} + dir=${dir%"$2"} + + printf '%s\n' "${dir:-/}" } ``` @@ -1112,6 +1115,9 @@ basename() { $ basename ~/Pictures/Wallpapers/1.jpg 1.jpg +$ basename ~/Pictures/Wallpapers/1.jpg .jpg +1 + $ basename ~/Pictures/Downloads/ Downloads ``` diff --git a/manuscript/chapter5.txt b/manuscript/chapter5.txt index 754a930..fce45ed 100644 --- a/manuscript/chapter5.txt +++ b/manuscript/chapter5.txt @@ -40,8 +40,11 @@ Alternative to the `basename` command. ```sh basename() { # Usage: basename "path" - : "${1%/}" - printf '%s\n' "${_##*/}" + dir=${1%${1##*[!/]}} + dir=${dir##*/} + dir=${dir%"$2"} + + printf '%s\n' "${dir:-/}" } ``` @@ -51,6 +54,9 @@ basename() { $ basename ~/Pictures/Wallpapers/1.jpg 1.jpg +$ basename ~/Pictures/Wallpapers/1.jpg .jpg +1 + $ basename ~/Pictures/Downloads/ Downloads ```