This matches how a non-timeout error is handled.
Details
- Reviewers
jilles - Commits
- rGe31fb97148f7: read builtin: Empty variables on timeout
read10.0 passed before, read11.0 failed before. Both pass.
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
This is more consistent, and probably more useful (while read loops tend not to treat EOF and read errors differently).
The whole error behaviour does not appear to match what most non-ash shells such as bash, ksh93, mksh and yash do (an immediate read error such as caused by <&- or 0>/dev/null leaves the variables unchanged), but POSIX seems to permit both (Consequences of errors in the read page "Default" pointing to XCU 1.4 Utility Description Defaults).
bin/sh/miscbltin.c | ||
---|---|---|
346 | It is possible, but I'm not sure it is better. Note that some ++ would have to be rearranged as well. | |
bin/sh/tests/builtins/read11.0 | ||
5 | Existing tests use mktemp -d, placing the fifo into a temporary directory, to avoid the discouraged -u option. | |
8 | Hmm, how portable is this? It is probably faster than forking off a child process to open the fifo for writing, which the standard requires and other tests do. | |
12 | Some other tests do stuff like [ "$r" -gt 128 ] && [ "$(kill -l "$r")" = TERM ] to avoid depending on signal numbers. |
bin/sh/miscbltin.c | ||
---|---|---|
346 | Yep, you're right. This version doesn't set the current argument to the empty string, and the other one does. You would have to ap++ before coming here. Never mind. |