Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Temporary Input Redirection in Bash

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
like image 363
Will Bickford Avatar asked Aug 31 '09 17:08

Will Bickford


2 Answers

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.

like image 191
Jeremy Bourque Avatar answered Nov 10 '22 23:11

Jeremy Bourque


maybe expect is what you want

like image 36
dfa Avatar answered Nov 10 '22 23:11

dfa