Search code examples
bashzshheredoc

stdin from heredoc not printing to screen?


I have a program that interactively logins a user. I used the heredoc to automate the process.

./login <<EOF
[email protected]
password
EOF

I was expecting the output would be something like this. This is what it displays when I run the program without the heredoc and type in username and password myself.

$ ./login
Enter your email: [email protected]
Enter your password: password
Successfully logged in.

However, I only see this.

$ ./login
Enter your email: 
Enter your password: 
Successfully logged in.

As you can see, all of the heredoc inputs are not printed out, even though the program seems to be getting the stdin correctly. What's the reason for this? It would be great if I could still see those inputs to help me debug problems. Thanks.


Solution

  • ECHO is a feature of the tty when users manually type chars to the tty. Your ./login << ... does not get input from the tty so the heredoc is not echoed. It's just like, for example,

    grep something < /some/file
    

    where you don't want it to echo the whole file's data.