Writes to standard output the full path name of your terminal.
/usr/bin/tty [ -s ]
The tty command writes the name of your terminal to standard output.
If your standard input is not a terminal and you do not specify the -s flag, you get the message Standard input is not a tty.
The following environment variables affect the execution of the tty command:
Item | Description |
---|---|
LANG | Determines the locale to use for the locale categories when neither the LC_ALL variable nor the corresponding environment variable beginning with LC_ specifies a locale. |
LC_ALL | Determines the locale to be used. This variable overrides any values for locale categories that are specified by any other environment variable beginning with LC_ or by the LANG variable. |
LC_CTYPE | Determines the locale for the interpretation of sequences of bytes of text data as characters. For example, this variable may specify multi-byte characters instead of single-byte characters. |
LC_MESSAGES | Determines the language for messages. |
Item | Description |
---|---|
-s | Suppresses reporting the path name. |
This command returns the following exit values:
Item | Description |
---|---|
0 | Standard input is a terminal. |
1 | Standard input is not a terminal. |
>1 | An error occurred. |
tty
if tty -s
then
echo 'Enter the text to print:' >/dev/tty
qprt -
fi
If the standard input is a terminal, this displays the message "Enter the text to print:" as a prompt and prints the text that the user types. If the standard input is not a terminal, this displays nothing; it merely prints the text read from the standard input.
The echo . . . >/dev/tty displays the prompt on the screen even if you redirect the standard output of the shell procedure. This way the prompt is never written into an output file. The special file /dev/tty always refers to your terminal, although it also has another name such as /dev/console or /dev/tty2.
Item | Description |
---|---|
/usr/bin/tty | Contains the tty command. |
/dev/tty | Specifies the tty pseudo device. |