LFCS · Question #863
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 echo command outputs "foo bar", which tee writes to a file named bar and also passes to cat, resulting in "foo bar" being printed to standard output.
Question
Options
- Acat
- Bfoo bar
- Ctee bar
- Dbar
- Efoo
How the community answered
(26 responses)- B88% (23)
- C4% (1)
- D8% (2)
Why each option
The `echo` command outputs "foo bar", which `tee` writes to a file named `bar` and also passes to `cat`, resulting in "foo bar" being printed to standard output.
`cat` is the command itself, and it will output its input, not its own name.
The `echo "foo bar"` command sends the string "foo bar" to its standard output. This output is then piped to `tee bar`, which simultaneously writes "foo bar" to a file named `bar` and forwards the same string "foo bar" to its standard output. Finally, `cat` receives "foo bar" as its standard input and prints it to the console.
`tee bar` is a command and arguments; the output of the pipeline is the data processed by the commands, not the command names.
`bar` is the name of the file created by `tee`, not the data being passed through the pipeline to standard output.
`foo` is only part of the string; the entire string "foo bar" is processed and output.
Concept tested: Command piping and `tee` utility
Source: https://www.gnu.org/software/coreutils/manual/html_node/tee-invocation.html
Topics
Community Discussion
No community discussion yet for this question.