tty outputs the path name of the terminal with which the process is linked. The exit status indicates whether or not standard input is a terminal.
If the process is linked with a virtual terminal, tty returns the name of the virtual terminal, not the real terminal.
Syntax
tty[ -s] |
Inhibits output of the terminal path name, returning the exit status only. -s not specified: |
Exit status
0 | Standard input is a terminal. |
1 | Standard input is not a terminal. |
>1 | An invalid option was specified. |
Error
The standard input is not a terminal and the -s option was not specified. |
Locale
The following environment variables affect the execution of tty: LANG Provide a default value for the internationalization variables that are unset or null. If LANG is unset of null, the corresponding value from the implementation-specific default locale will be used. If any of the internationalization variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalization variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments and input files), the classification of characters as upper- to lower-case, and the mapping of characters from one case to the other. LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogs for the processing of LC_MESSAGES. |
Example 1
Output the name of the current terminal:
|
Example 2
The following script is to send output to the screen even if standard output is redirected to a file: . . echo 'Output to the terminal' > `tty` . . |
Example 3
The following script is to generate an error message if standard input is not the terminal: . . if tty -s then read input . . else echo 'Standard input is not a terminal' >&2 fi . . |