6

I have a script, script1, that operates on standard input. I can call that script from script2

#!/bin/sh ./script1 

script1 then operates on standard input to script2. I can also pipe some other input to script1

#!/bin/sh echo "Called from script2" | ./script1 

But then ./script1 does not use the standard input at all.

What I want is to prepend the standard input to script1 by the input "Called from script2". Is this possible?

I know how to do this with a temp file, but I am wondering if there's a way to not use a temporary file.

1 Answer 1

10
#!/bin/sh { echo 'some text' cat } | ./script1 

or

#!/bin/sh { echo 'some text'; cat; } | ./script1 

Use cat to forward the standard input of your wrapper script to script1.

In the examples above, I pipe the combined output of the preceding compound command (the { ...; } bit) to your script1 script. The input of cat is the standard input stream of your wrapper script, and cat would reproduce it on its output stream after echo has produced its output.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.