bible: fix dirname. Closes #76
This commit is contained in:
parent
6508ca0c9d
commit
ea8fd2369c
10
README.md
10
README.md
|
@ -1061,7 +1061,11 @@ Alternative to the `dirname` command.
|
|||
```sh
|
||||
dirname() {
|
||||
# Usage: dirname "path"
|
||||
printf '%s\n' "${1%/*}/"
|
||||
dir=${1%%/}
|
||||
|
||||
[[ $dir == */* ]] || dir=.
|
||||
|
||||
printf '%s\n' "${dir%/*}"
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -1069,10 +1073,10 @@ dirname() {
|
|||
|
||||
```shell
|
||||
$ dirname ~/Pictures/Wallpapers/1.jpg
|
||||
/home/black/Pictures/Wallpapers/
|
||||
/home/black/Pictures/Wallpapers
|
||||
|
||||
$ dirname ~/Pictures/Downloads/
|
||||
/home/black/Pictures/
|
||||
/home/black/Pictures
|
||||
```
|
||||
|
||||
## 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
|
||||
read_sleep() {
|
||||
# Usage: sleep 1
|
||||
# sleep 0.2
|
||||
# Usage: read_sleep 1
|
||||
# read_sleep 0.2
|
||||
read -rt "$1" <> <(:) || :
|
||||
}
|
||||
```
|
||||
|
|
|
@ -9,7 +9,11 @@ Alternative to the `dirname` command.
|
|||
```sh
|
||||
dirname() {
|
||||
# Usage: dirname "path"
|
||||
printf '%s\n' "${1%/*}/"
|
||||
dir=${1%%/}
|
||||
|
||||
[[ $dir == */* ]] || dir=.
|
||||
|
||||
printf '%s\n' "${dir%/*}"
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -17,10 +21,10 @@ dirname() {
|
|||
|
||||
```shell
|
||||
$ dirname ~/Pictures/Wallpapers/1.jpg
|
||||
/home/black/Pictures/Wallpapers/
|
||||
/home/black/Pictures/Wallpapers
|
||||
|
||||
$ dirname ~/Pictures/Downloads/
|
||||
/home/black/Pictures/
|
||||
/home/black/Pictures
|
||||
```
|
||||
|
||||
## Get the base-name of a file path
|
||||
|
|
Loading…
Reference in New Issue