1

I want to pipe the output of a program to another program in addition to STDOUT. The way I am doing it right now is to tee the output to a temporary file that I then delete but would be interested in knowing about better approaches where I don't have to create a temp file. Here is my code that shows what I am doing right now:

random=`echo $RANDOM`
filename='/tmp/'$random
foo | tee $filename
cat $filename | bar
rm $filename

In above foo and bar are my programs. What I want is to pipe the output of foo to bar but also have foo display its output to STDOUT. If I just do:

foo | bar

the output to STDOUT is lost.

1
  • 1
    have tee write to the process's console instead of a temp file? e.g. foo | tee /dev/tty | bar? Commented Feb 29, 2016 at 18:11

2 Answers 2

4

you can use process substitution:

foo | tee >(bar)

the >(…) syntax is for taking the bytes written to "this file" and giving them to the inner process

Sign up to request clarification or add additional context in comments.

Comments

0

foo can contain:

Message = $message ./bar.sh

bar can contain:

echo I received the \"$message"\

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.