8

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.

1 Answer 1

9

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.

1
  • 46 seconds faster.
    – Catherine
    Nov 22, 2010 at 23:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .