Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
    
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! –  o0rebelious0o Feb 5 at 23:52

1 Answer 1

up vote 2 down vote accepted

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

share|improve this answer
    
What does doubling up on stdin do ? how does that work ? –  X Tian Feb 6 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 at 0:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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