Count the number of lines generated by generate-items with wc.
Do not save the generated text in an intermediate file.
Which command sequence is appropriate?
The pipe makes generate-items standard output become wc -l standard input, allowing counting without an intermediate file.
Detailed explanation
generate-items | wc -lCorrect. generate-items | wc -l counts the generated newline-delimited output.
Correct. generate-items | wc -l counts the generated newline-delimited output.
generate-items > wc -lIncorrect. This redirects output to a file named wc and does not create a pipeline.
Incorrect. This redirects output to a file named wc and does not create a pipeline.
wc -l | generate-itemsIncorrect. The direction is reversed, so wc does not receive generate-items output.
Incorrect. The direction is reversed, so wc does not receive generate-items output.
generate-items ; wc -lIncorrect. ; leaves wc reading the terminal rather than the previous command's output.
Incorrect. ; leaves wc reading the terminal rather than the previous command's output.
Try it yourself
An example you can run in a temporary verification environment.
printf 'a\nb\nc\n' | wc -lExpected result
3Key points
- Data flows left to right
- wc -l counts stdin lines
- No intermediate file is needed
Notes
- Environment: POSIX shell / GNU wc / 標準入力
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.