tty - return user's terminal name
tty
tty -s
The tty utility writes to the standard output the name of the terminal that is open as standard input. The name that is used is equivalent to the string that would be returned by the XSH specification ttyname() function.
The tty utility supports the XBD specification, Utility Syntax Guidelines .The following option is supported:
- -s
- Do not write the terminal name. Only the exit status will be affected by this option. The terminal status will be determined as if the XSH specification isatty() function were used.
None.
While no input is read from standard input, standard input will be examined to determine whether or not it is a terminal, and, if so, to determine the name of the terminal.
None.
The following environment variables affect the execution of tty:
- LANG
- Provide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation 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 internationalisation 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).
- LC_MESSAGES
- Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error and informative messages written to standard output.
- NLSPATH
- Determine the location of message catalogues for the processing of LC_MESSAGES .
Default.
If the -s option is specified, standard output will 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 the XSH specification ttyname() will be written in the following format:
"%s\n", <terminal name>
Otherwise, a message will be written indicating that standard input is not connected to a terminal. In the POSIX locale, the tty utility will use the format:
"not a tty\n"
Used only for diagnostic messages.
None.
None.
The following exit values are returned:
- 0
- Standard input is a terminal.
- 1
- Standard input is not a terminal.
- >1
- 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. Portable applications should use test -t 0.
None.
None.
The XSH specification description of isatty(), ttyname().