Post History
As you've observed, programs like less don't rely on STDIN for interactive input. Instead, they look for their controlling terminal and open a new file descriptor reading from that. On most syste...
#1: Initial revision
As you've observed, programs like `less` don't rely on STDIN for interactive input. Instead, they look for their *controlling terminal* and open a new file descriptor reading from that. On most systems, that's achieved by opening `/dev/tty` for reading. Much as with STDIN/STDOUT/STDERR, a Unix process usually inherits its controlling terminal from its parent, in this case the shell. See also [tty(4)](https://manpages.debian.org/stable/manpages/tty.4.en.html) and [credentials(7)](https://manpages.debian.org/stable/manpages/credentials.7.en.html). Another program that does this is `sudo`, which is why you can type things like: ``` echo foo | sudo tee /root/bar ``` and it'll work even if `sudo` wants a password. What's more, it uses the controlling terminal for printing the password prompt too, so you could even do: ``` cut -d: -f1 /etc/passwd | sudo xargs getent shadow | less ``` and it still works.
