shell 输出如何影响命令提示符后键入的文本?

Qua*_*odo 8 shell bash prompt terminal

我以前经历过类似的行为,但直到现在我才能重现它:影响下一个命令提示符后文本的命令的输出,准备Enter由用户编辑。

以下面的例子为例:

cat /usr/share/terminfo/a/ansi
Run Code Online (Sandbox Code Playgroud)

具有以下效果:

在此处输入图片说明

或者,复制并粘贴:

1%dP1%dM1%dB1%d@1%dS1%dL1%dD1%dC1%dT1%dA%p1%c2%{1}%-%db%p1%dd
1%t;7%;%?%p2%t;4%;%?%p3%t;7%;%?%p4%t;5%;%?%p6%t;1%;%?%p7%t;8%;%?%p9%t;11%;m +%d;%dR;0123456789]c1%dm1%dmAX[user@untrusted ~]$ R65;1;9c
Run Code Online (Sandbox Code Playgroud)

如您所见,R65;1;9c出现在命令提示符之后,按下Enter它会将其评估为命令。

我确实记得文本不仅出现在命令行之后,而且还被再次执行的情况,可能是因为它包含换行符。

这可以被认为是错误还是预期的行为,某种不可打印字符的组合允许在下一个命令提示符之后写入?

Edu*_*ani 3

您看到的是终端的属性字符串。终端可能会对这些命令中的一个或多个做出不同的响应。

重现它们的快速方法:

$ echo -e '\033[c'
Run Code Online (Sandbox Code Playgroud)

就我而言,在Gnome terminal这个types 65;1;9c内部,在xterm它的types 64;1;2;6;9;15;18;21;22c内部,在控制台中,按 Ctrl-Alt-F1 后,我得到6c.

这些字符串是由终端创建的,因此您不能使用它们来“插入”任意文本。

本页详细介绍了它们的含义:

   CSI Ps c  Send Device Attributes (Primary DA).
          Ps = 0  or omitted -> request attributes from terminal.  The
          response depends on the decTerminalID resource setting.
            -> CSI ? 1 ; 2 c  ("VT100 with Advanced Video Option")
            -> CSI ? 1 ; 0 c  ("VT101 with No Options")
            -> CSI ? 6 c  ("VT102")
            -> CSI ? 6 2 ; Psc  ("VT220")
            -> CSI ? 6 3 ; Psc  ("VT320")
            -> CSI ? 6 4 ; Psc  ("VT420")
          The VT100-style response parameters do not mean anything by
          themselves.  VT220 (and higher) parameters do, telling the
          host what features the terminal supports:
            Ps = 1  -> 132-columns.
            Ps = 2  -> Printer.
            Ps = 3  -> ReGIS graphics.
            Ps = 4  -> Sixel graphics.
            Ps = 6  -> Selective erase.
            Ps = 8  -> User-defined keys.
            Ps = 9  -> National Replacement Character sets.
            Ps = 1 5  -> Technical characters.
            Ps = 1 8  -> User windows.
            Ps = 2 1  -> Horizontal scrolling.
            Ps = 2 2  -> ANSI color, e.g., VT525.
            Ps = 2 9  -> ANSI text locator (i.e., DEC Locator mode).
Run Code Online (Sandbox Code Playgroud)

某些设备还将使用以下转义序列输出设备的识别信息(请求终端参数)。

$ echo -e '\033[x'
Run Code Online (Sandbox Code Playgroud)