010-160 · Question #21
Which of the following commands sorts the output of the command export-logs?
The correct answer is D. export-logs | sort. The pipe operator (|) chains commands by sending the stdout of one command as stdin to the next, enabling output sorting.
Question
Options
- Aexport-logs < sort
- Bexport-logs > sort
- Cexport-logs & sort
- Dexport-logs | sort
- Eexport-logs <> sort
How the community answered
(36 responses)- A3% (1)
- C3% (1)
- D94% (34)
Why each option
The pipe operator (|) chains commands by sending the stdout of one command as stdin to the next, enabling output sorting.
The < operator redirects a file as input to a command; it cannot redirect one command's output into another command.
The > operator redirects a command's output to a file named 'sort', not to the sort utility itself.
The & operator runs export-logs in the background and then runs sort independently, with no data connection between the two processes.
The pipe operator | sends the standard output of export-logs directly to the sort utility as standard input, allowing sort to process and alphabetically order the results. This is the standard Unix/Linux mechanism for chaining command output through filters like sort, grep, or awk without intermediate files.
The <> operator opens a file descriptor for both reading and writing simultaneously; it is not used to chain two commands together.
Concept tested: Unix pipe operator for command output chaining
Source: https://www.gnu.org/software/bash/manual/bash.html#Pipelines
Topics
Community Discussion
No community discussion yet for this question.