国际访客建议访问 Primers 编程伙伴 国际版站点 > Bash 教程 > tty 以获得更好的体验。

# Bash 的 tty 命令

tty [OPTION]...

!subtitle:功能

查看连接到标准输入的终端文件名。

!subtitle:类型

可执行文件(/usr/bin/tty),属于 coreutils

!subtitle:参数

  • OPTION 选项:

    • -s, --silent, --quiet - 不打印任何内容,仅通过返回值返回状态

    • --help - 显示帮助

    • --version - 显示版本

!subtitle:返回值

  • 0 - 标准输入是终端

  • 1 - 标准输入是非终端文件

  • 2 - 参数错误

  • 3 - 发生写错误

  • 5 - 无法确认终端名称

# 示例

$ tty
/dev/pts/7

# 推荐阅读

# 手册

TTY(1)                           User Commands                          TTY(1)

NAME
       tty - print the file name of the terminal connected to standard input

SYNOPSIS
       tty [OPTION]...

DESCRIPTION
       Print the file name of the terminal connected to standard input.

       -s, --silent, --quiet
              print nothing, only return an exit status

       --help display this help and exit

       --version
              output version information and exit

AUTHOR
       Written by David MacKenzie.

REPORTING BUGS
       GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
       Report any translation bugs to <https://translationproject.org/team/>

COPYRIGHT
       Copyright  ©  2023  Free Software Foundation, Inc.  License GPLv3+: GNU
       GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
       This is free software: you are free  to  change  and  redistribute  it.
       There is NO WARRANTY, to the extent permitted by law.

SEE ALSO
       Full documentation <https://www.gnu.org/software/coreutils/tty>
       or available locally via: info '(coreutils) tty invocation'

GNU coreutils 9.4                 April 2024                            TTY(1)
本文 更新于: 2026-03-06 09:52:35 创建于: 2026-03-06 09:52:35