开发者

How does these special characters work in Perl?

print "\e开发者_JAVA技巧[4m", $prompt, "\e[24m", "\e[1m";

It seems it doesn't work in bash:

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


"\e" means ESC which is used for VT100 escape sequences and similar. Perl understands the "\e" escape sequence in strings and interprets it as a the ESC character (it can also be written as "\33" or "\x1b").

To use ESC with echo, supply the -e option which enables these escapes to be processed:

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

The transformation from the two characters "\e" to the single ESC character (with the value 0x1B) is done by echo itself (with -e) -- the shell does not handle the escapes which appear in quotes. The link for echo above also includes an example of such usage.

Happy coding.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜