[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]

Commands Reference, Volume 5


tty Command

Purpose

Writes to standard output the full path name of your terminal.

Syntax

/usr/bin/tty-s ]

Description

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:

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.

Flags


-s Suppresses reporting the path name.

Exit Status

This command returns the following exit values:

0 Standard input is a terminal.
1 Standard input is not a terminal.
>1 An error occurred.

Examples

  1. To display the full path name of your display:

    tty
    
  2. To test whether or not the standard input is a terminal:
    if tty - s
    then
    echo 'Enter the text to print:' >/dev/tty
    fi
    qprt

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.

Files


/usr/bin/tty Contains the tty command.
/dev/tty Specifies the tty pseudo device.

Related Information

The National Language Support Overview for Programming in AIX 5L Version 5.1 General Programming Concepts: Writing and Debugging Programs discusses the LC_ variables.


[ Previous | Next | Table of Contents | Index | Library Home | Legal | Search ]