standard input: not a tty

5,540

Solution 1

Those are redirections:

So instead of "not a tty", you could say "is a redirection". Redirect a file into a command:

command < filename    

Here Documents - This type of redirection instructs the shell to read input from the current source until a line containing only word (with no trailing blanks) is seen:

<<[-]word
        here-document
delimiter

Redirect stdout of commandA to commandB:

commandA | commandB

Solution 2

It can be a file (even a device file or FIFO) or a pipeline.

The difference is important because you can operate on a controlling terminal in more ways than on a regular opened file. Sometimes this is advantageous, sometimes it is disadvantageous.

For example you cannot redirect the terminal. You can redirect stdin but that does not affect reads from the tty. Often programs read passwords from the tty. This can be nice because it does not interfere with data you want the command to read from stdin but it can be bad if you want to script the command (and need e.g. expect or socat for handling the terminal).

But a process still has a controlling tty even if it is not connected to stdin.

Share:
5,540

Related videos on Youtube

user1730706
Author by

user1730706

Hello world

Updated on September 18, 2022

Comments

  • user1730706
    user1730706 over 1 year

    Sometimes standard input (stdin) is a terminal:

    $ tty
    /dev/pts/0
    

    Sometimes not:

    $ echo hello | tty
    not a tty
    
    $ tty < /dev/null
    not a tty
    
    $ tty << eof
    > hello
    > eof
    not a tty
    

    When "stdin" is not a terminal, what is it? Does that "not a tty" group have a collective name, or are they all just referred to individually?