mirror of
https://github.com/dylanaraps/pure-bash-bible.git
synced 2025-01-17 04:08:17 +01:00
docs: update
This commit is contained in:
parent
300a0fe11e
commit
968a1bd80f
@ -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%/*}
|
||||
|
||||
|
@ -5,6 +5,8 @@
|
||||
Enabling `extdebug` allows access to the `BASH_ARGV` array which stores
|
||||
the current function’s 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
|
||||
|
@ -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
15
test.sh
@ -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() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user