LX0-103 · Question #50
When given the following command line. echo "foo bar" | tee bar | cat Which of the following output is created?
The correct answer is B. foo bar. The tee command writes its input to a file and passes it through to stdout, so cat receives and displays 'foo bar'.
Question
When given the following command line. echo "foo bar" | tee bar | cat Which of the following output is created?
Options
- Acat
- Bfoo bar
- Ctee bar
- Dbar
- Efoo
How the community answered
(27 responses)- A11% (3)
- B81% (22)
- C4% (1)
- E4% (1)
Why each option
The tee command writes its input to a file and passes it through to stdout, so cat receives and displays 'foo bar'.
cat is a command name, not output; it reads its stdin from the tee pipe and prints the received data, not its own name.
echo outputs 'foo bar' to stdout, which is piped to tee. The tee command writes the data to the file named 'bar' and simultaneously passes the same data to its own stdout. cat then reads from that pipe and prints 'foo bar' to the terminal, making 'foo bar' the only visible output.
tee bar is the command invocation, not output; tee writes data to the file 'bar' and forwards the stream, it does not print its own syntax.
bar is the filename that tee writes to on disk; the string 'foo bar' is what appears on the terminal, not the filename alone.
foo is only part of the input string; the full string 'foo bar' passes unchanged through both tee and cat to the terminal.
Concept tested: tee command stdout passthrough in a pipeline
Source: https://man7.org/linux/man-pages/man1/tee.1.html
Topics
Community Discussion
No community discussion yet for this question.