Open System Services Shell and Utilities Reference Manual (G06.25+, H06.03+)
Table Of Contents
User Commands (t - u) tty(1)
NAME
tty - Returns pathname of terminal device
SYNOPSIS
tty [-s]
The tty command writes the full pathname of your terminal device to standard output.
FLAGS
-s Suppresses reporting the pathname so that only the exit status is affected. (Obsoles-
cent.) You can perform the same operation with the test -t file_descriptor command.
DESCRIPTION
The tty -s command evaluates as TRUE if standard output is a display and FALSE if it is not.
The /dev/tty special file always refers to your controlling terminal, although it also may have
another name like /dev/console or /dev/tty2. To avoid writing undesirable output to an output
file (for example, to write a prompt in a shell script to the screen, while writing the response to
the prompt to an output file), redirect standard output to /dev/tty.
EXAMPLES
1. To display the full pathname of your terminal device, enter:
tty
2. To test whether or not the standard input is a terminal device, enter:
if test -t 0
then
echo "Output is a display"
else
echo "Output is not a display"
FILES
/dev/tty Pseudodevice representing the user’s controlling terminal.
DIAGNOSTICS
not a tty Your standard input is not an interactive terminal.
EXIT VALUES
The exit value has the following possible meanings:
0 Standard input is a tty.
1 Standard input is not a tty.
2 Invalid flags specified or other error.
RELATED INFORMATION
Commands: stty(1).
Subroutines: isatty(3), ttyname(3).
Files: tty(7).
527188-003 Hewlett-Packard Company 9−23