I am starting entr
as a subshelled background process as described in its man page to listen to changes to some file foo, occuring during interactive use of some program baz
, and I would like to terminate that background process on completion of baz
:
(echo foo | entr echo bar &) && baz;
I found this question which tries to get the process id of a background process started in this way, which seems very convoluted to do in bash. Is there some way to kill it?
(...)
subshell in the firstplace? (also notice that the&&
is misleading, the exit status of(... &)
is always zero). Why not justecho foo | entr echo bar & baz; kill $!
? – mosvy Oct 16 at 14:18-n
option for non-interactive mode -- but I have not used thatentr
utility. Anyways, a more reliable and non-racy way to run a command with no/dev/tty
on Linux is withsetsid command ...
, rather then exploiting the quirks of the subshell implementation (which depend from one shell to another). – mosvy Oct 17 at 9:07