dirname: fix another case

This commit is contained in:
Dylan Araps 2019-09-19 17:38:33 +03:00
parent 49bd538c26
commit a2c0d36e19
3 changed files with 5 additions and 4 deletions

View File

@ -1067,10 +1067,9 @@ Alternative to the `dirname` command.
dirname() {
# Usage: dirname "path"
dir=${1%%/}
[[ "${dir##*/*}" ]] && dir=.
dir=${dir%/*}
[[ $1 == */* ]] || dir=.
printf '%s\n' "${dir:-/}"
}
```

View File

@ -10,10 +10,9 @@ Alternative to the `dirname` command.
dirname() {
# Usage: dirname "path"
dir=${1%%/}
[[ "${dir##*/*}" ]] && dir=.
dir=${dir%/*}
[[ $1 == */* ]] || dir=.
printf '%s\n' "${dir:-/}"
}
```

View File

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