2

If I have a pipe like cat /dev/somedevice | grep 'test' that output commands, like for example echo 'test 17', the commands appear in realtime (everytime /dev/somedevice delivers some line). If I however pipe the commands to sh, they won't be invoked imediately because of pipe buffering. So

cat /dev/somedevice | grep 'test' | sh

wont execute commands in realtime.

Is there any other way that would? With xargs or something?

3
  • So you want sh to interprete each line separately as soon as each is fed to sh?
    – theoden8
    Aug 6, 2015 at 13:23
  • 1
    See my answer to a very similar question cat /dev/smd | stdbuf -o0 grep 'test' | stdbuf -o0 sh Aug 6, 2015 at 16:17
  • The stdbuf method works, so the answer to this question is almost the same as to "how to get unbuffered pipes" questions all around.. Maybe you post a similiar answer?
    – dronus
    Aug 10, 2015 at 10:28

1 Answer 1

3

Try --line-buffered to make a continuous stream:

cat /dev/somedevice | grep --line-buffered 'test' | sh
1
  • This is nice, but works for example pipe only (using grep). I would favor a more general answer like in the comments above.
    – dronus
    Aug 10, 2015 at 10:29

You must log in to answer this question.

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