nerdexam
CompTIA

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'.

GNU and Unix Commands

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)
  • A
    11% (3)
  • B
    81% (22)
  • C
    4% (1)
  • E
    4% (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'.

Acat

cat is a command name, not output; it reads its stdin from the tee pipe and prints the received data, not its own name.

Bfoo barCorrect

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.

Ctee bar

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.

Dbar

bar is the filename that tee writes to on disk; the string 'foo bar' is what appears on the terminal, not the filename alone.

Efoo

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

#tee#pipes#standard output#command pipeline

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice