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?

  • So you want sh to interprete each line separately as soon as each is fed to sh? – theoden Aug 6 '15 at 13:23
  • See my answer to a very similar question cat /dev/smd | stdbuf -o0 grep 'test' | stdbuf -o0 sh – Felipe Lema Aug 6 '15 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 '15 at 10:28

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

cat /dev/somedevice | grep --line-buffered 'test' | sh
  • 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 '15 at 10:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.