$ (echo foo;sleep 10;echo bar)|time grep -q foo;echo $?0.00user 0.00system 
0:00.00elapsed 50%CPU (0avgtext+0avgdata 2432maxresident)k0inputs+0outputs 
(0major+107minor)pagefaults 0swaps0$  

The shell hangs for 10 seconds on its child pids but grep does not!
    On Thursday, March 21, 2024 at 11:03:49 AM EDT, Niels Möller 
<ni...@lysator.liu.se> wrote:  
 
 Niels Möller <ni...@lysator.liu.se> writes:

> E.g., if I run 
>
>  (printf foo ; sleep 30) | grep -q foo
>
> I want grep to exit successfully right away. Currently, grep waits until
> it gets EOF on the input, 30 seconds later.

Sorry if I'm confused about how to script this. The following (bash
syntax) is a better example:

  grep -q foo <(sh -c 'printf foo ; sleep 30' &)

This blocks 30 seconds before exiting. In contrast, 

  grep -q foo <(sh -c echo foo ; sleep 30' &)

(only difference is the newline at the end of the line) does exit
immediately.

Regards,
/Niels

-- 
Niels Möller. PGP key CB4962D070D77D7FCB8BA36271D8F1FF368C6677.
Internet email is subject to wholesale government surveillance.



  

Reply via email to