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.
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)- A6% (2)
- B3% (1)
- C3% (1)
- D71% (22)
- E16% (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.
foo is a command not an output file, and nothing in this command redirects foobar's stdout to foo.
The pipe does not save output to a file named foobar; it streams foo's stdout to foobar's stdin in memory.
The pipe operator | connects stdout only, not stderr, from foo to foobar's stdin.
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.
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
Community Discussion
No community discussion yet for this question.