On this page
reference
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
| Option | Effect |
|---|---|
-s, --silent |
Print nothing; report the answer only through the exit status. |
Exit status
| Code | Meaning |
|---|---|
0 |
Standard input is a terminal. |
1 |
Standard input is not a terminal. |
2 |
A usage error. |
See also
Peios Learn
Built with Trail