bible: fix dirname. Closes #76
This commit is contained in:
10
README.md
10
README.md
@@ -1061,7 +1061,11 @@ Alternative to the `dirname` command.
|
|||||||
```sh
|
```sh
|
||||||
dirname() {
|
dirname() {
|
||||||
# Usage: dirname "path"
|
# Usage: dirname "path"
|
||||||
printf '%s\n' "${1%/*}/"
|
dir=${1%%/}
|
||||||
|
|
||||||
|
[[ $dir == */* ]] || dir=.
|
||||||
|
|
||||||
|
printf '%s\n' "${dir%/*}"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -1069,10 +1073,10 @@ dirname() {
|
|||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ dirname ~/Pictures/Wallpapers/1.jpg
|
$ dirname ~/Pictures/Wallpapers/1.jpg
|
||||||
/home/black/Pictures/Wallpapers/
|
/home/black/Pictures/Wallpapers
|
||||||
|
|
||||||
$ dirname ~/Pictures/Downloads/
|
$ dirname ~/Pictures/Downloads/
|
||||||
/home/black/Pictures/
|
/home/black/Pictures
|
||||||
```
|
```
|
||||||
|
|
||||||
## Get the base-name of a file path
|
## Get the base-name of a file path
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ Surprisingly, `sleep` is an external command and not a `bash` built-in.
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
read_sleep() {
|
read_sleep() {
|
||||||
# Usage: sleep 1
|
# Usage: read_sleep 1
|
||||||
# sleep 0.2
|
# read_sleep 0.2
|
||||||
read -rt "$1" <> <(:) || :
|
read -rt "$1" <> <(:) || :
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -9,7 +9,11 @@ Alternative to the `dirname` command.
|
|||||||
```sh
|
```sh
|
||||||
dirname() {
|
dirname() {
|
||||||
# Usage: dirname "path"
|
# Usage: dirname "path"
|
||||||
printf '%s\n' "${1%/*}/"
|
dir=${1%%/}
|
||||||
|
|
||||||
|
[[ $dir == */* ]] || dir=.
|
||||||
|
|
||||||
|
printf '%s\n' "${dir%/*}"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -17,10 +21,10 @@ dirname() {
|
|||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ dirname ~/Pictures/Wallpapers/1.jpg
|
$ dirname ~/Pictures/Wallpapers/1.jpg
|
||||||
/home/black/Pictures/Wallpapers/
|
/home/black/Pictures/Wallpapers
|
||||||
|
|
||||||
$ dirname ~/Pictures/Downloads/
|
$ dirname ~/Pictures/Downloads/
|
||||||
/home/black/Pictures/
|
/home/black/Pictures
|
||||||
```
|
```
|
||||||
|
|
||||||
## Get the base-name of a file path
|
## Get the base-name of a file path
|
||||||
|
|||||||
2
test.sh
2
test.sh
@@ -116,7 +116,7 @@ test_count() {
|
|||||||
|
|
||||||
test_dirname() {
|
test_dirname() {
|
||||||
result="$(dirname "/home/black/Pictures/Wallpapers/1.jpg")"
|
result="$(dirname "/home/black/Pictures/Wallpapers/1.jpg")"
|
||||||
assert_equals "$result" "/home/black/Pictures/Wallpapers/"
|
assert_equals "$result" "/home/black/Pictures/Wallpapers"
|
||||||
}
|
}
|
||||||
|
|
||||||
test_basename() {
|
test_basename() {
|
||||||
|
|||||||
Reference in New Issue
Block a user