diff --git a/src/builtin_read.cpp b/src/builtin_read.cpp index 9b7586f2a..453a9df64 100644 --- a/src/builtin_read.cpp +++ b/src/builtin_read.cpp @@ -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; } diff --git a/tests/read.in b/tests/read.in index 7230e4cfc..59eddcdfd 100644 --- a/tests/read.in +++ b/tests/read.in @@ -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) diff --git a/tests/read.out b/tests/read.out index 5dd8f66a2..d486f4af9 100644 --- a/tests/read.out +++ b/tests/read.out @@ -130,3 +130,5 @@ Multi-char delimiters with IFS a b ..c + +banana sausage