views:

282

answers:

3

I am looking for a way to dump input into my terminal from a file, but when EOF is reached I would like input returned back to my keyboard. Is there a way to do this with Bash (or any other commonly-available *nix shell)?

Details: I am debugging a server program which executes a fork to start a child process. Every time I start a debugging session with gdb I have to type set follow-fork-mode child. I would like to use some sort of input redirection to have this pre-populated. There are other uses as well that I can think of, so I'd prefer a general solution - hence the reason this question is not about gdb.

Solution: start-server.sh

#!/bin/bash
cat run-server.txt - |/bin/bash

run-server.txt

gdb ./Server
set follow-fork-mode child
run
+1  A: 

maybe expect is what you want

dfa
+1 I can see how to have it help me generate a script - I'll look into what sorts of things expect can do. Thanks for the link. So far I don't think it answers my question.
Will Bickford
http://expect.nist.gov/example/dislocate.man.html looks promising
Will Bickford
Overall I think expect is a nice tool. I'll have to dig into it - jbourque's solution was more in line with what I was asking though.
Will Bickford
A: 

Maybe use an intermediate file? Assuming you want to run the script myscript.sh:

INPUT_FILE=input.txt
TEMP_FILE=`mktemp -t input`
myscript.sh < $TEMP_FILE &
cat $INPUT_FILE >> $TEMP_FILE
cat >> $TEMP_FILE
+6  A: 

You can do this:

cat input_file - | program

That will concatenate input_file followed by stdin to program, which I think is what you want.

jbourque
+1 That explains when I use "|vi -" I think. I had found that somewhere and never looked into what it *meant.* This may be the ticket.
Will Bickford
It's confusing when you use angle brackets as if they were quotation marks, since they are used for redirection.
Dennis Williamson
Dennis: That's a good point. I'll change them.
jbourque