I need to achieve a particular effect using bash's redirection facilities.

I know that I can redirect a file to some program's standard input:

[user@host]$ application < file.txt

The thing is, I'd like to know can I regain control of this program's input after the file content's have been passed to it. In other words, I'd like to run a command similar to the above, and then, instead of the termination of the application, I'd want it to wait for further commands from standard input (keyboard).

As I write this question, it occured to me that I could probably write another application (or a script), that would at first write some data to standard output and then act as echo, like:

[user@host]$ stdin_proxy.sh | application

Would it work, and is there any better way to do so? There are a bunch of Googleable tutorials covering this issue, but they all amount to one advice - "reopen the stdin after the file contents have been read". Hovewer, I don't have the access to the source code of application.

link|improve this question

67% accept rate
feedback

1 Answer

up vote 3 down vote accepted

cat can do this easily enough.

cat file.txt - | application

Note that this won't fool the application into thinking that it's actually connected to a terminal; you'll need unbuffer for that.

link|improve this answer
46 seconds faster. – whitequark Nov 22 '10 at 23:23
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.