tty

tty prints the name of the terminal connected to standard input.

tty [options]
$ tty
/dev/pts/3

If standard input is not a terminal — because it has been redirected from a file or a pipe — tty prints not a tty instead.

That second behaviour is the useful one: a script can run tty to find out whether it is being run interactively or as part of a pipeline, and behave accordingly.

Options #

OptionEffect
-s, --silentPrint nothing; report the answer only through the exit status.

Exit status #

CodeMeaning
0Standard input is a terminal.
1Standard input is not a terminal.
2A usage error.

Edit this page