docs: update
This commit is contained in:
parent
300a0fe11e
commit
968a1bd80f
|
@ -1070,7 +1070,8 @@ Alternative to the `dirname` command.
|
||||||
```sh
|
```sh
|
||||||
dirname() {
|
dirname() {
|
||||||
# Usage: dirname "path"
|
# Usage: dirname "path"
|
||||||
dir=${1%%/}
|
dir=${1:-.}
|
||||||
|
dir=${dir%%${dir##*[!/]}}
|
||||||
[[ "${dir##*/*}" ]] && dir=.
|
[[ "${dir##*/*}" ]] && dir=.
|
||||||
dir=${dir%/*}
|
dir=${dir%/*}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
Enabling `extdebug` allows access to the `BASH_ARGV` array which stores
|
Enabling `extdebug` allows access to the `BASH_ARGV` array which stores
|
||||||
the current function’s arguments in reverse.
|
the current function’s arguments in reverse.
|
||||||
|
|
||||||
|
**CAVEAT**: Requires `shopt -s compat44` in `bash` 5.0+.
|
||||||
|
|
||||||
**Example Function:**
|
**Example Function:**
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
@ -41,6 +43,8 @@ allows us to effectively remove array duplicates.
|
||||||
|
|
||||||
**CAVEAT:** Requires `bash` 4+
|
**CAVEAT:** Requires `bash` 4+
|
||||||
|
|
||||||
|
**CAVEAT:** List order may not stay the same.
|
||||||
|
|
||||||
**Example Function:**
|
**Example Function:**
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
|
|
|
@ -9,7 +9,8 @@ Alternative to the `dirname` command.
|
||||||
```sh
|
```sh
|
||||||
dirname() {
|
dirname() {
|
||||||
# Usage: dirname "path"
|
# Usage: dirname "path"
|
||||||
dir=${1%%/}
|
dir=${1:-.}
|
||||||
|
dir=${dir%%${dir##*[!/]}}
|
||||||
[[ "${dir##*/*}" ]] && dir=.
|
[[ "${dir##*/*}" ]] && dir=.
|
||||||
dir=${dir%/*}
|
dir=${dir%/*}
|
||||||
|
|
||||||
|
|
15
test.sh
15
test.sh
|
@ -129,6 +129,21 @@ test_dirname() {
|
||||||
|
|
||||||
result="$(dirname "something/")"
|
result="$(dirname "something/")"
|
||||||
assert_equals "$result" "."
|
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() {
|
test_basename() {
|
||||||
|
|
Loading…
Reference in New Issue