docs: update

This commit is contained in:
Dylan Araps 2019-09-19 18:43:16 +03:00
parent 300a0fe11e
commit 968a1bd80f
4 changed files with 23 additions and 2 deletions

View File

@ -1070,7 +1070,8 @@ Alternative to the `dirname` command.
```sh
dirname() {
# Usage: dirname "path"
dir=${1%%/}
dir=${1:-.}
dir=${dir%%${dir##*[!/]}}
[[ "${dir##*/*}" ]] && dir=.
dir=${dir%/*}

View File

@ -5,6 +5,8 @@
Enabling `extdebug` allows access to the `BASH_ARGV` array which stores
the current functions arguments in reverse.
**CAVEAT**: Requires `shopt -s compat44` in `bash` 5.0+.
**Example Function:**
```sh
@ -41,6 +43,8 @@ allows us to effectively remove array duplicates.
**CAVEAT:** Requires `bash` 4+
**CAVEAT:** List order may not stay the same.
**Example Function:**
```sh

View File

@ -9,7 +9,8 @@ Alternative to the `dirname` command.
```sh
dirname() {
# Usage: dirname "path"
dir=${1%%/}
dir=${1:-.}
dir=${dir%%${dir##*[!/]}}
[[ "${dir##*/*}" ]] && dir=.
dir=${dir%/*}

15
test.sh
View File

@ -129,6 +129,21 @@ test_dirname() {
result="$(dirname "something/")"
assert_equals "$result" "."
result="$(dirname "//")"
assert_equals "$result" "/"
result="$(dirname "//foo")"
assert_equals "$result" "/"
result="$(dirname "")"
assert_equals "$result" "."
result="$(dirname "something//")"
assert_equals "$result" "."
result="$(dirname "something/////////////////////")"
assert_equals "$result" "."
}
test_basename() {