Merge pull request #66 from amiryal/read_sleep
Implement sleep without reading from stdin of the caller
This commit is contained in:
commit
d3135ded2c
14
README.md
14
README.md
|
@ -1913,7 +1913,7 @@ Surprisingly, `sleep` is an external command and not a `bash` built-in.
|
||||||
read_sleep() {
|
read_sleep() {
|
||||||
# Usage: sleep 1
|
# Usage: sleep 1
|
||||||
# sleep 0.2
|
# sleep 0.2
|
||||||
read -rst "${1:-1}" -N 999
|
read -rt "$1" <> <(:) || :
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -1925,6 +1925,18 @@ read_sleep 0.1
|
||||||
read_sleep 30
|
read_sleep 30
|
||||||
```
|
```
|
||||||
|
|
||||||
|
For performance-critical situations, where it is not economic to open and close an excessive number of file descriptors, the allocation of a file descriptor may be done only once for all invocations of `read`:
|
||||||
|
|
||||||
|
(See the generic original implementation at https://blog.dhampir.no/content/sleeping-without-a-subprocess-in-bash-and-how-to-sleep-forever)
|
||||||
|
|
||||||
|
```shell
|
||||||
|
exec {sleep_fd}<> <(:)
|
||||||
|
while some_quick_test; do
|
||||||
|
# equivalent of sleep 0.001
|
||||||
|
read -t 0.001 -u $sleep_fd
|
||||||
|
done
|
||||||
|
```
|
||||||
|
|
||||||
## Check if a program is in the user's PATH
|
## Check if a program is in the user's PATH
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
|
|
Loading…
Reference in New Issue