super trainee
super trainee

Reputation: 117

Infinite loop issue when passing answers

I want to only pass the first answer to a function

echo "y" | install

and let the choice to the user to answer the next questions , but when i do that i get a infinite loop.

Upvotes: 0

Views: 70

Answers (2)

Etan Reisner
Etan Reisner

Reputation: 81052

Joachim Pileborg's answer is entirely correct however for some usages you could use something like { echo y; cat } | install to send a leading y and then accept user input after that but that's only going to work for some circumstances/usages (it won't report character-by-character to the program for example).

If you really do need something like this then you can look into using the expect program as it was designed for this (among other things).

Upvotes: 2

Some programmer dude
Some programmer dude

Reputation: 409472

When using pipes, the shell changes so that the receiving programs standard input is the pipe and nothing else. You can't mix input from a pipe with un-piped input from the shell, it's simply not possible. When using pipes (or redirection) it's all or nothing.

Regarding the install program, what you think is an "infinite loop" is probably that it tries to read from standard input (which is the pipe), but as there is nothing more to read from the pipe it will simply wait for more input to arrive, which doesn't happen.

Upvotes: 6

Related Questions