【发布时间】: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
【问题讨论】:
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
【问题讨论】:
"\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 的链接也包含了这种用法的示例。
编码愉快。
【讨论】:
man terminfo 了解更多信息。