Question 151
System ManagementA user runs ls /nonexistent | wc -l in Bash. What appears on the terminal?
Show the answer
Correct answerC. The error message from ls and the count 0 from wc
AWhy not this: The error goes to stderr, which the pipe does not carry, so wc never sees it; that would need 2>&1 or |&.
BWhy not this: The pipe does not discard stderr; it simply is not connected to it, so the error still reaches the terminal.
CWhy this is right: The pipe carries only stdout, so the error from ls goes to the terminal and wc counts 0 lines.
DWhy not this: wc still prints a count when its input is empty, so it shows 0 rather than nothing.
A pipe connects stdout of the first command to stdin of the second. Stderr is not connected to the pipe unless it is redirected with 2>&1 or |&, so the error goes to the terminal and wc reports 0.