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.
generate-items > wc -lIncorrect. 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.
generate-items ; wc -lIncorrect. ; 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 / 標準入力
- Use temporary files and harmless commands for stream experiments.
- Shell redirection syntax and xargs behavior should be checked on the target shell implementation.
Foundation review
Place the operation
The downstream counter sees the upstream stream rather than the command's terminal display.
Check the side effect
Compare the count with the known number of generated records.