Skip to content

Commit a8824db

Browse files
committed
docs: update
1 parent d3135de commit a8824db

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

manuscript/chapter19.txt

+13-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Surprisingly, `sleep` is an external command and not a `bash` built-in.
1212
read_sleep() {
1313
# Usage: sleep 1
1414
# sleep 0.2
15-
read -rst "${1:-1}" -N 999
15+
read -rt "$1" <> <(:) || :
1616
}
1717
```
1818

@@ -24,6 +24,18 @@ read_sleep 0.1
2424
read_sleep 30
2525
```
2626

27+
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`:
28+
29+
(See the generic original implementation at https://blog.dhampir.no/content/sleeping-without-a-subprocess-in-bash-and-how-to-sleep-forever)
30+
31+
```shell
32+
exec {sleep_fd}<> <(:)
33+
while some_quick_test; do
34+
# equivalent of sleep 0.001
35+
read -t 0.001 -u $sleep_fd
36+
done
37+
```
38+
2739
## Check if a program is in the user's PATH
2840

2941
```shell

0 commit comments

Comments
 (0)