Reputation: 70
I am currently trying to debug some scripts I've made and I cannot find a way for a 'read' instruction to be executed.
To summarize, I've got two functions, one with a 'while read lines' that is called after a pipe, and another functions that read user input after while read is processed.
Let me now explain this with code :
echo "$lines" | saveLines
saveLines(){
# ...
while read line ; do
# processing lines
done
myOtherFunction
}
myOtherFunction(){
echo "I am here !" # <= This is printed in console
read -p "Type in : " tmp # <= Input is never asked to user, and the message is not printed
echo "I now am here !" # <= This is printed in console
}
This code is simplified but the spirit is here. I tried to insert a 'read' instruction before the 'read -p ...', it did not seems to change things...
So please, if you can show my error or tell me why this behavior is expected, I would be very happy. Thanks for you time
Upvotes: 0
Views: 165
Reputation: 14723
This question is very close to that other question, in a slightly different context. To be more precise and as explained by the OP, the command run was
echo "$lines" | saveLines
meaning that the standard input of the code executed by saveLines wasn't the terminal anymore, but the same descriptor as the standard output of the echo...
command.
To solve this it thus suffices to replace
…
read -p "Type in : " tmp
…
with
…
read -p "Type in : " tmp </dev/tty
…
Upvotes: 1