无关本文比较的TTY

TTY is a toolbox for developing beautiful command line clients in Ruby
with a fluid interface for gathering input, querying terminal
properties and displaying information.

github
官网


但此处比较的不是这个RUBY命令行工具。

控制台,终端,tty,shell等概念的区别

What is the exact difference between a ‘terminal’, a ‘shell’, a ‘tty’ and a ‘console’?

终端,Shell,“tty”和控制台(console)有什么区别?

(以下内容皆从上述链接中复制粘贴整理所得,侵删致歉)

A terminal is at the end of an electric wire, a shell is the home of a turtle, tty is a strange abbreviation and a console is a kind of cabinet.

In unix terminology, the short answer is that

terminal = tty = text input/output environment(文本的输入输出环境)
console = physical terminal(物理终端)
shell = command line interpreter(命令行解释器)

Teleprinter(TTY)& Terminal

电传打字机TTY

A teleprinter (teletypewriter, Teletype or TTY) is an
electromechanical typewriter that can be used to send and receive
typed messages through various communications channels, in both
point-to-point and point-to-multipoint configurations.

The name “terminal” came from the electronic point of view, and the name “console” from the furniture point of view. Very early in unix history, electronic keyboards and displays became the norm for terminals.

终端(terminal)这个名字是从电子的观点来看的,而控制台(console)是从设备的角度来看的。
在UNIX历史的极早期阶段,电子键盘和显示器就已经是一种规范的终端

a tty is a particular kind of device file which implements a number of additional commands (ioctls) beyond read and write.
tty在读写控制外实现特殊命令。

terminal is synonymous with tty.
通常意义上终端是tty同义词。

Some ttys are provided by the kernel on behalf of a hardware device, for example with the input coming from the keyboard and the output going to a text mode screen, or with the input and output transmitted over a serial line. Other ttys, sometimes called pseudo(伪)-ttys, are provided (through a thin kernel layer) by programs called terminal emulators(模拟器), such as Xterm (running in the X Window System), Screen (which provides a layer of isolation between a program and another terminal), Ssh (which connects a terminal on one machine with programs on another machine), Expect (for scripting terminal interactions), etc.

有的tty由(软件)内核来代替硬件设备,比如从键盘发送过来的input,以及发送到文本模式的屏幕上的output,或者在串行线上传输的input/output流。还有一种tty——有时候叫做伪tty(pseudo-ttys)的,它是由叫做”终端模拟器“的程序提供的(通过一个中间层),这种tty例如Xterm(运行在X window系统上),Screen(在一个程序和另一个终端之间提供了中间层),SSH(在另一台电脑上,通过程序连接另一台电脑上的终端),Expect(用脚本和终端交互)。

The word terminal can also have a more traditional meaning of a device through which one interacts with a computer, typically with a keyboard and display. For example an X terminal is a kind of thin client, a special-purpose computer whose only purpose is to drive a keyboard, display, mouse and occasionally other human interaction peripherals(外围交互设备), with the actual applications running on another, more powerful computer.

terminal这个词通常也有一个更加传统的意思,表示一台能够用来和电脑交互的设备——通常有显示器和键盘。
比如一个X terminal,它唯一的作用就是驱动键盘,显示器,鼠标,(偶尔还有)别的外围交互设备;而实际上程序是泡在另外一台更加强大的计算机上的。

Console

A console is generally a terminal in the physical sense that is by some definition the primary terminal(主终端) directly connected to a machine. The console appears to the operating system as a (kernel-implemented) tty. On some systems, such as Linux and FreeBSD, the console appears as several ttys (special key combinations switch between these ttys); just to confuse matters, the name given to each particular tty can be “console”, ”virtual console”, ”virtual terminal”, and other variations.

控制台通常是物理意义上的终端,其通过某种定义直接连接到机器的主终端。
在一些操作系统(比如Linux和FreeBSD)上console一般有好几个tty(用特定的组合键能够在这些tty之间切换)。有时候这些命名让人混乱,比如操作系统可能把那些tty叫做”console“ ”virtual console“ ”virtual terminal“之类的。

Why is a Virtual Terminal “virtual”, and what/why/where is the “real” Terminal?

Shell

A shell is the primary interface that users see when they log in, whose primary purpose is to start other programs. (I don’t know whether the original metaphor is that the shell is the home environment for the user, or that the shell is what other programs are running in.)

shell,作为用户登录系统时看到的主界面,它主要的用处就是启动别的程序。(我不确定原来的比喻义是指shell是用户的home环境,还是说shell是其他程序在里面跑的环境)

In unix circles, shell has specialized to mean a command-line shell, centered around entering the name of the application one wants to start, followed by the names of files or other objects that the application should act on, and pressing the Enter key. Other types of environments don’t use the word “shell”; for example, window systems involve “window managers” and “desktop environments”, not a “shell”.

在UNIX圈里,shell 特指命令行shell(并且围绕这这样的描述: “输入你想要运行的应用名字,后面跟着参数,并按回车键。”) 其他类型的环境并不使用“shell”这个词,比如说窗口系统涉及了”窗口管理器“(window managers) 和”桌面环境“(desktop environments),但并不使用”shell“这个词。

There are many different unix shells. Popular shells for interactive use include Bash (the default on most Linux installations), zsh (which emphasizes power and customizability) and fish (which emphasizes simplicity).

比较流行的交互式shell包括bash(大多数Linux发行版的默认选择) zsh(重视功能和可定制性) 还有fish(以简单为主旨)。

In unix system administration, a user’s shell is the program that is invoked when they log in. Normal user accounts have a command-line shell, but users with restricted access may have a restricted shell or some other specific command (e.g. for file-transfer-only accounts).

在UNIX系统管理中,一个用户的shell是那个在登录的时候被调用的程序。普通用户账户也拥有命令行shell,受限的用户(比如仅用于传输文件的账户)可能拥有一个受限的shell,或者只能运行特定命令的shell。

tasks of terminal and shell

  • Input: the terminal converts keys into control sequences (e.g. Left
    \e[D). The shell converts control sequences into commands (e.g. \e[D
    backward-char).
    终端把键盘操作转换成控制序列,shell再转换控制序列为命令

  • Line editing, input history and completion are provided by the shell.
    The terminal may provide its own line editing, history and completion instead, and only send a line to the shell when it’s ready to be executed. The only common terminal that operates in this way is M-x shell in Emacs.
    行编辑(line editon)中,输入历史和输入补全功能是shell提供的。
    终端有时候会在它自己的行编辑功能中提供输入历史和输入补全功能,并且在命令要执行时通过line发送到shell中。唯一这样做的主流terminal就是Emacs里的M-x。

  • Output: the shell emits instructions such as “display foo”, “switch
    the foreground color to green”, “move the cursor to the next line”,
    etc. The terminal acts on these instructions.
    输出:shell发出指令,而终端就响应这些指令。

  • The prompt is purely a shell concept.
    命令提示符是纯粹的shell概念。

  • The shell never sees the output of the commands it runs (unless
    redirected). Output history (scrollback) is purely a terminal
    concept.
    shell永远看不到它所运行的命令的输出(除非重定向),输出历史(回滚)仅仅是个终端上的概念。

  • Inter-application copy-paste is provided by the terminal (usually
    with the mouse or key sequences such as Ctrl+Shift+V or
    Shift+Insert). The shell may have its own internal copy-paste
    mechanism as well (e.g. Meta+W and Ctrl+Y).
    应用程序之间的复制粘贴是由终端提供的(通常用鼠标,或者组合键,比如Ctrl+SHift+V 或Shift+Insert)。 Shell可能有它自己的内部复制粘贴机制(比如Meta+Y,Ctrl+Y)。

  • Job control (launching programs in the background and managing them)
    is mostly performed by the shell. However, it’s the terminal that
    handles key combinations like Ctrl+C to kill the foreground job and
    Ctrl+Z to suspend it.
    作业控制(在后台启动程序,并且管理这些程序)主要是由shell执行。不过,是由终端来处理组合键的(比如Ctrl+C 杀死前台程序,或者Ctrl+Z终止任务运行)。