LFCS · Question #787
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 the command foo < bar | foobar, the foo command reads its input from the file bar, and its standard output is then redirected as the standard input for the foobar command.
Question
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
(69 responses)- B3% (2)
- C1% (1)
- D94% (65)
- E1% (1)
Why each option
In the command `foo < bar | foobar`, the `foo` command reads its input from the file `bar`, and its standard output is then redirected as the standard input for the `foobar` command.
The output of `foobar` is not saved to `foo`; `foobar` receives input from `foo` via the pipe.
The stdout of `foo` is piped to `foobar` as stdin, not saved to a file named `foobar`.
The pipe (`|`) primarily redirects standard output to standard input, not standard error (stderr).
The pipe symbol (`|`) redirects the standard output (stdout) of the command `foo` to become the standard input (stdin) of the `foobar` command.
The command `bar` is actually a file whose content is provided as standard input to the `foo` command, not a command receiving input from `foobar`.
Concept tested: Linux shell I/O redirection and pipes
Source: https://man7.org/linux/man-pages/man1/bash.1.html
Topics
Community Discussion
No community discussion yet for this question.