0

I have a pipeline like so:

 tail -n0 -f "${my_input}" | ql_receiver_lock_holder | while read line; do echo "$line" >> "${my_output}"; # xxx: how can I programmatically close the pipeline at this juncture? done & disown; 

my question: is there a way to programmatically close the pipeline where it says xxx? I could probably just call exit 0; but I am wondering if there is a way to close the current pipeline somehow.

2
  • 2
    What effect do you want to achieve here? Read a single line of input? If so, why use while at all? ql_receiver_lock_holder | (read line; echo ...) & disown would work just as well for that. Or do you want to end the loop? In which case a simple break would do. Commented Apr 23, 2018 at 6:04
  • For me this sound like you want to break out of the loop, but it is really difficult to understand what you want to archive. Commented Apr 24, 2018 at 7:21

1 Answer 1

2

In:

tail -n0 -f -- "$my_input" | ql_receiver_lock_holder | sed /xxx/q > "$my_output" 
  • sed would exit after reading the first line containing xxx.
  • ql_receiver_lock_holder would then exit (killed by a SIGPIPE) upon the first write it does to stdout (the now broken pipe) after that.
  • Likewise, tail would exit upon the first write it does after that.

If you want ql_receiver_lock_holder and tail to exit as soon as sed exits without waiting for their next write to stdout, you can use approaches described at

Note that this kind of while read loop is not the right way to process text in shells. At the very least, you'd need something like:

while IFS= read -r line; do printf '%s\n' "$line" case $line in (*xxx*) break esac done 

to replace the sed /xxx/q but which would be terribly inefficient except for very small input.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.