halfwolf 写了:谢谢两位,我又重新尝试了tusooa在5楼提供的方案,完全可行,在上次试验时‘’误用为“”,故导致结果不合预期,谢谢!
可行的方法汇总如下
1、直接派
--------------------
PS3="Whats the^[[49;31m book ^[[0mmean?"
PS3='Whats the^[[49;31m book ^[[0mmean?'
2、$派
--------------------
PS3=$'Whats the\e[49;31m book \e[0mmean?'
PS3=$'Whats the\033[49;31m book \033[0mmean?'
PS3=$'Whats the^[[49;31m book ^[[0mmean?'
PS3=$"Whats the^[[49;31m book ^[[0mmean?"
3、$(echo -e )派
--------------------
PS3=$(echo -e 'Whats the\033[49;31m book \033[0mmean?')
PS3=$(echo -e 'Whats the\e[49;31m book \e[0mmean?')
PS3=$(echo -e 'Whats the^[[49;31m book ^[[0mmean?')
PS3=$(echo -e "Whats the\033[49;31m book \033[0mmean?")
PS3=$(echo -e "Whats the\e[49;31m book \e[0mmean?")
PS3=$(echo -e "Whats the^[[49;31m book ^[[0mmean?")
以下是我的学习体验,请指导,谢谢!
--------------------
\033、\e、^[ 比较:^[通用性最强,\033与\e相同;
“”、‘’比较:‘’通用性比“”强
方法3:通过$()进行echo操作,将带颜色的信息赋予PS3;
方法1:标准的正则表达;
方法2:很酷,但没搞明白$''是什么意思,一种操作,还是其他?
[bash] Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as
specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows:
\a alert (bell)
\b backspace
\e
\E an escape character
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\\ backslash
\' single quote
\" double quote
\nnn the eight-bit character whose value is the octal value nnn (one to three digits)
\xHH the eight-bit character whose value is the hexadecimal value HH (one or two hex digits)
\cx a control-x character
The expanded result is single-quoted, as if the dollar sign had not been present.
A double-quoted string preceded by a dollar sign ($"string") will cause the string to be translated according to the current
locale. If the current locale is C or POSIX, the dollar sign is ignored. If the string is translated and replaced, the
replacement is double-quoted.
[/bash]
就是扩展了转义字符啊。