I want to do a tail -F on a file until matching a pattern. I found a way using awk, but IMHO my command is not really clean. The problem is that I need to d
sh -c 'tail -n +0 --pid=$$ -f /tmp/foo | { sed "/EOF/ q" && kill $$ ;}'
Here the main problem is with $$
.
If you run command as is, $$
is set not to sh but to the PID of the current shell where command is run.
To make kill work you need to change kill $$
to kill \$$
After that you can safely get rid of --pid=$$
passed to tail command.
Summarising, following will work just fine:
/bin/sh -c 'tail -n 0 -f /tmp/foo | { sed "/EOF/ q" && kill \$$ ;}
Optionally you can pass -n
to sed
to keep it quiet :)