Will Bickford
Will Bickford

Reputation: 5386

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

Upvotes: 5

Views: 1532

Answers (3)

Jeremy Bourque
Jeremy Bourque

Reputation: 3543

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.

Upvotes: 8

user156605
user156605

Reputation: 130

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

Upvotes: 0

dfa
dfa

Reputation: 116304

maybe expect is what you want

Upvotes: 1

Related Questions