mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-12 13:08:49 +00:00
Fix read to stdout output appearing first
echo banana (read) will output whatever read reads _first_ because it uses a direct write_loop(). This also removes some duplicate code.
This commit is contained in:
parent
701259d372
commit
ea49c14c62
3 changed files with 7 additions and 6 deletions
|
@ -394,11 +394,6 @@ static int validate_read_args(const wchar_t *cmd, read_cmd_opts_t &opts, int arg
|
|||
return STATUS_CMD_OK;
|
||||
}
|
||||
|
||||
void write_stdout(wcstring val) {
|
||||
const std::string &out = wcs2string(val);
|
||||
write_loop(STDOUT_FILENO, out.c_str(), out.size());
|
||||
}
|
||||
|
||||
/// The read builtin. Reads from stdin and stores the values in environment variables.
|
||||
int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
||||
wchar_t *cmd = argv[0];
|
||||
|
@ -446,7 +441,7 @@ int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
|||
}
|
||||
|
||||
if (opts.to_stdout) {
|
||||
write_stdout(buff);
|
||||
streams.out.append(buff);
|
||||
return exit_res;
|
||||
}
|
||||
|
||||
|
|
|
@ -247,3 +247,7 @@ begin
|
|||
echo a...b...c | read -l a b c
|
||||
echo $a; echo $b; echo $c
|
||||
end
|
||||
echo
|
||||
|
||||
# At one point, whatever was read was printed _before_ banana
|
||||
echo banana (echo sausage | read)
|
||||
|
|
|
@ -130,3 +130,5 @@ Multi-char delimiters with IFS
|
|||
a
|
||||
b
|
||||
..c
|
||||
|
||||
banana sausage
|
||||
|
|
Loading…
Reference in a new issue