Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I would like to do auto testing one of my scripts and here documents are almost perfect. It would be nice however to be able to copy the STDIN to STDOUT so it's just as if it was typed in when the here document is pushed into the script (see the inputs on every run). Is this easily doable?

I have at the moment (doesn't show input as user would type and see, only shows output):

#!/bin/sh

make && ./proj <<- EOF
i
3
i
9
i
55
i
345
t
s
33
s
455
i
44
i
99
t
q
EOF
share|improve this question

3 Answers 3

up vote 1 down vote accepted

You could duplicate it with tee, and then use fd3 to sneak it around your script with something like this:

{ make && tee /dev/fd/3 <<EOF | ./proj
1
3
i
9
EOF
} 3>&1

...but I wouldn't trust anything other than the version of bash I tested this on to parse it the same way. Darth's suggestion of using a temp file would work, or if there's not too much input you could do essentially the same thing with a variable:

input='1
3
i
9'
make && echo "$input" && echo "$input" | ./proj

...although this also may break on a few shells that can't cope with linebreaks in variable values.

share|improve this answer

You can also use redirection. Save your test input into test.txt, and then make && ./proj < test.txt

share|improve this answer

You want cat.

share|improve this answer

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.