Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

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.

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

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.