read: Don't use chunking read with --line

Fixes a regression from #8552.
This commit is contained in:
Fabian Homborg 2022-03-14 08:01:56 +01:00
parent dc5bdda8e0
commit cd62771d12
2 changed files with 11 additions and 0 deletions

View file

@ -501,6 +501,10 @@ maybe_t<int> builtin_read(parser_t &parser, io_streams_t &streams, const wchar_t
read_interactive(parser, buff, opts.nchars, opts.shell, opts.silent, opts.prompt,
opts.right_prompt, opts.commandline, streams.stdin_fd);
} else if (!opts.nchars && !stream_stdin_is_a_tty &&
// "one_line" is implemented as reading n-times to a new line,
// if we're chunking we could get multiple lines so we would have to advance
// more than 1 per run through the loop. Let's skip that for now.
!opts.one_line &&
(streams.stdin_is_directly_redirected || lseek(streams.stdin_fd, 0, SEEK_CUR) != -1)) {
// We read in chunks when we either can seek (so we put the bytes back),
// or we have the bytes to ourselves (because it's directly redirected).

View file

@ -375,3 +375,10 @@ echo foo\nbar\nbaz | begin
echo $bar
# CHECK: bar
end
begin
echo 1
echo 2
end | read -l --line foo bar
echo $foo $bar
# CHECK: 1 2