【问题标题】:How does these special characters work in Perl?这些特殊字符在 Perl 中是如何工作的?
【发布时间】:2011-10-15 17:04:11
【问题描述】:
print "\e[4m", $prompt, "\e[24m", "\e[1m";

似乎在 bash 中不起作用:

[root@dev-test ~]$ echo "\e[4mhello world\e[24m\e[1m"
\e[4mhello world\e[24m\e[1m

【问题讨论】:

    标签: perl bash terminal


    【解决方案1】:

    "\e" 表示用于VT100 escape sequences 和类似的ESC。 Perl 理解字符串中的"\e" escape sequence 并将其解释为 ESC 字符(也可以写为“\33”或“\x1b”)。

    要将 ESC 与 echo 一起使用,请提供 -e 选项,以便处理这些转义:

    echo -e "\e[4mhello world\e[24m\e[1m"
    

    从两个字符“\e”到单个 ESC 字符(值为 0x1B)的转换是由echo 本身(使用-e)完成的——shell 不处理出现在引号中的转义.上面echo 的链接也包含了这种用法的示例。

    编码愉快。

    【讨论】:

    • 那么所有终端都是VT100终端??
    • @new_perl:几乎所有这些都模拟 VT100,有或没有扩展。请参阅man terminfo 了解更多信息。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-10
    • 1970-01-01
    • 1970-01-01
    • 2021-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多