1

I am trying to create a script capable of infinitely processing an incoming stream which is piped to it, and continuous producing an output stream which can be piped to something else something as follows:

<infinitely produce data stream> | myscript | <use modified stream>

In my case, I have a program which will continously generate a headerless wav sinusoid which will be piped into my script which will mix it with other sinusoids, and pass it out to a program which will play it as it streams in.

I have tried using

#!/bin/bash

while read data; do
    #echo "data = $data"
    ./merge <($data) <(./sine 1000)
done

But this just leaves crazy symbols all over my terminal. It looks like for everyline of stdin it receives, it calls merge again and again.

My merge program is written in C and is written such that it is opening a file passed as an argument.

It works fine when I run in in the terminal as

./merge <(./sine 1000) <(./sine 2000) | ./audio_sink

This has two instances of sine running, generating 1kHz and 2kHz sine wave respectively, and merge reads the two input streams, mixes them, and produces an output to sdtout which can then be piped to audio_sink and I can hear it is working.

In this script I'm writing I need to be able to pipe the input directing into the first argument as above.

How can you write a bash script which allows you to use data continuously piped into it, manipulate it, and have the data piped back out?

1
  • You sir, are a genius... You have no idea how many hours I've spent on this.... Stick that as an answer and I'll mark it right!
    – rcbevans
    Feb 5, 2014 at 23:52

1 Answer 1

3

perhaps ./merge <(cat) <(./sine 1000)

2
  • What does doubling up on stdin do ? how does that work ?
    – X Tian
    Feb 6, 2014 at 0:05
  • That's taking input from 2 sources. One is STDIN (<(cat)) the 2nd is taking input from sine. The cat simply takes the data that comes in on STDOUT from the previous pipe, and directs it via STDIN to merge. BTW Glenn, very elegant solution!
    – slm
    Feb 6, 2014 at 0:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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