Tty command

From Linux Shell Scripting Tutorial - A Beginner's handbook
Jump to navigation Jump to search

The tty command will display the file name of the terminal connected to standard input i.e. the name of the current terminal. It displays not a tty message if standard input is not a terminal.


tty command exit status

You can use the following exit status in a shell script:

  • 0 if standard input is a terminal
  • 1 if standard input is not a terminal
  • 2 if given incorrect arguments
  • 3 if a write error occurs

Examples

To display your current terminal connected to standard input, enter:

tty

Sample outputs:

/dev/pts/0

OR

echo "Your current terminal $(tty)"

Where,

See also