Pass list-services standard output to grep and display only lines containing active.
Do not create a temporary file.
Which command is appropriate?
| connects the left command's standard output to the right command's standard input, creating a direct stream between them.
Detailed explanation
list-services > grep activeIncorrect. This treats grep as a redirection target rather than a following command.
list-services < grep activeIncorrect. < connects input and does not invoke grep as a filter.
list-services ; grep activeIncorrect. ; runs commands sequentially without passing data.
list-services | grep activeCorrect. list-services | grep active sends the stream into grep.
Try it yourself
An example you can run in a temporary verification environment.
printf 'active api\ninactive old\nactive db\n' | grep '^active'Expected result
active api
active dbKey points
- A pipe connects stdout to stdin
- No temporary file is needed
- stderr is not piped by default
Notes
- Environment: POSIX shell / grep / 生成した標準入力
- 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
A pipeline avoids an intermediate file and lets each command process a stream incrementally.
Check the side effect
Use a finite input so the pipeline's output and exit status are easy to inspect.