TTY(1) General Commands Manual TTY(1)

ttyreturn user’s terminal name

tty

Obsolescent Version:

tty -s

The tty utility shall write to the standard output the name of the terminal that is open as standard input. The name that is used shall be equivalent to the string that would be returned by the POSIX. 1 {8} () function.

The tty utility shall conform to the utility argument syntax guidelines described in 2.10.2. The following option shall be supported by the implementation:

(Obsolescent.) Do not write the terminal name. Only the exit status shall be affected by this option. The terminal status shall be determined as if the POSIX. 1 {8} () function were used.

None.

While no input is read from standard input, standard input shall be examined to determine whether or not it is a terminal, and/or to determine the name of the terminal.

None.

The following environment variables shall affect the execution of tty:

This variable shall determine the locale to use for the locale categories when both LC_ALL and the corresponding environment variable (beginning with LC_ ) do not specify a locale. See 2.6.

This variable shall determine the locale to be used to override any values for locale categories specified by the settings of LANG or any environment variables beginning with LC_.

For the obsolescent version, this variable shall determine the locale for the interpretation of sequences of bytes of text data as characters (e.g., single- versus multibyte characters in arguments).

This variable shall determine the language in which messages should be written.

Default.

If the −s option is specified, standard output shall not be used. If the −s option is not specified and standard input is a terminal device, a pathname of the terminal as specified by POSIX. 1 {8} () shall be written in the following format: "%s\n", <terminal name> Otherwise, a message shall be written indicating that standard input is not connected to a terminal. In the POSIX Locale, the tty utility shall use the format: "not a tty \n"

Used only for diagnostic messages.

None.

None.

The tty utility shall exit with one of the following values:

Standard input is a terminal.

Standard input is not a terminal.

An error occurred.

Default.

This utility checks the status of the file open as standard input against that of a system-defined set of files. It is possible that no match can be found, or that the match found need not be the same file as that which was opened for standard input (although they are the same device). The −s option is useful only if the exit code is wanted. It does not rely on the ability to form a valid pathname. The −s option was made obsolescent because the same functionality is provided by test -t 0, but not dropped completely because historical scripts depend on this form.

The definition of tty was made more explicit to explain the difference between a tty and a pathname of a tty.

September 1991 posix.fail