I have Bash script that is used to process data, which is sent through a pipe from another process.
I'm trying to add a functionality that causes and exits after a certain condition is met, whose simplified representation is:
( while true; do date; sleep 1; done ) | ( for ((i = 0; i < 3; i++)); do read -r line; echo LINE: $line; sleep 1; done; exit 1 )
In the real case:
- the command after the pipe is included in (and replaced by) a script;
- the command before the pipe is a binary executable, and I don't have control over its internals.
I've also tried to close stdin:
( while true; do date; sleep 1; done ) | ( for ((i = 0; i < 3; i++)); do read -r line; echo LINE: $line; sleep 1; done; exec 0<&- )
However, when the condition is met, nothing is sent to stdout, but the left program still runs.
How can I accomplish the task?
|
symbol. Otherwise, you mustbreak
thefor
loop when the condition is met. – AlexP Dec 11 '19 at 12:23