% xkbset -repeatkeys
% xinput test 14 | grep -m 1 "key release 36"

and holding the second return, nothing happens, as expected. After releasing the second return, I get

key release 36

Now I would expect the programme to exit immediately, but instead it waits for an additional keypress---even shift works---, before exiting. I suppose this makes xinput produce an additional line, but I don't see why that should be necessary---grep has already found the line it was looking for. So why doesn't it exit immediately?

PS. The answer seems correct, and I was able to get the desired result by doing

% xinput test 14 | { grep -m 1 "key release 36" && killall xinput ; }

1 Answer 1


grep probably does exit after the first match. It's xinput that's still running: it only notices the pipe is closed the next time it tries to output something.

For example, here only the first pgrep finds a running grep process, but the sleep on the left-hand side still happens.

$ ( pgrep grep >&2; echo xxx; pgrep grep >&2; sleep 3; echo yyy ) |grep -m1 xxx

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .