nerdexam
CompTIA

LX0-103 · Question #187

In the command foo < bar | foobar, which of the following statements is correct?

The correct answer is D. The command foobar receives its stdin from the stdout of foo.. In 'foo < bar | foobar', the pipe connects foo's stdout to foobar's stdin, while the less-than operator feeds the file bar as foo's stdin.

GNU and Unix Commands

Question

In the command foo < bar | foobar, which of the following statements is correct?

Options

  • AThe stdout from the command foobar is saved to the file foo.
  • BThe stdout from the command foo is saved to the file foobar.
  • CThe command foobar receives its stdin from the stderr of foo.
  • DThe command foobar receives its stdin from the stdout of foo.
  • EThe command bar receives its stdin from the contents of the file foobar.

How the community answered

(31 responses)
  • A
    6% (2)
  • B
    3% (1)
  • C
    3% (1)
  • D
    71% (22)
  • E
    16% (5)

Why each option

In 'foo < bar | foobar', the pipe connects foo's stdout to foobar's stdin, while the less-than operator feeds the file bar as foo's stdin.

AThe stdout from the command foobar is saved to the file foo.

foo is a command not an output file, and nothing in this command redirects foobar's stdout to foo.

BThe stdout from the command foo is saved to the file foobar.

The pipe does not save output to a file named foobar; it streams foo's stdout to foobar's stdin in memory.

CThe command foobar receives its stdin from the stderr of foo.

The pipe operator | connects stdout only, not stderr, from foo to foobar's stdin.

DThe command foobar receives its stdin from the stdout of foo.Correct

The pipe operator | takes the standard output of the left-hand command (foo) and connects it directly to the standard input of the right-hand command (foobar). The < operator independently redirects the contents of the file bar as stdin for foo, so the data flow is: bar feeds foo, and foo's output feeds foobar.

EThe command bar receives its stdin from the contents of the file foobar.

bar is a file whose contents are fed to foo via input redirection (<); bar is not a command and does not receive any input itself.

Concept tested: Linux shell piping and input redirection behavior

Source: https://www.gnu.org/software/bash/manual/bash.html#Redirections

Topics

#pipes#I/O redirection#stdin/stdout#shell pipelines

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice