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.
Incorrect. 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.
Incorrect. < connects input and does not invoke grep as a filter.
list-services ; grep activeIncorrect. ; runs commands sequentially without passing data.
Incorrect. ; runs commands sequentially without passing data.
list-services | grep activeCorrect. list-services | grep active sends the stream into grep.
Correct. 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 / 生成した標準入力
- 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.