BASH: echo -e 不适用于 Unicode Cyrillic
BASH: echo -e does not work with Unicode Cyrillic
我最近切换到另一个工作机器并在使用西里尔文时遇到问题。我的 Bash 脚本从应用程序获取新消息并使用它们。
然而,这些消息大多是用西里尔字母写的,我得到的结果类似于“\u043f\u0440\u0438\u0432\u0456\u0442”
在我的 运行 Ubuntu 旧系统上,我可以使用 echo -e
轻松将其转换为普通字母
[18:18 deimos@nc ~] echo -e "\u043f\u0440\u0438\u0432\u0456\u0442"
привіт
不幸的是,它不适用于 CentOS 6 上的新系统。
[15:21] [server1.nichan.net ~] # echo -e "\u043f\u0440\u0438\u0432\u0456\u0442"
\u043f\u0440\u0438\u0432\u0456\u0442
两个系统都是英文的。 CentOS 是今天刚安装的,所以没有太多内容。到目前为止我在上面安装的唯一东西是 pip 和我的脚本需要的一些 Python 模块,所以可以肯定地说系统是新的。
此外,其他 Unicode 符号似乎也能正常工作。唯一的问题是西里尔文:
[15:21] [server1.nichan.net ~] # echo -e "\xE2\x98\xA0"
☠
如有任何帮助,我们将不胜感激。
UPD:看来我的 Bash 已经过时了。我有 4.1,这个功能至少需要 4.3。我使用本指南更新了 Bash:
wget https://ftp.gnu.org/pub/gnu/bash/bash-4.3.tar.gz
tar xvfz bash-4.3.tar.gz
cd bash-4.3/
./configure
make
ls -la bash
cp -f bash /bin/bash
/bin/bash
\Uxxxx
echo
和 printf
参数中的 Unicode 文字支持已添加到 bash
4.2。
来自change log:
This document details the changes between this version, bash-4.2-alpha,
and the previous version, bash-4.1-release.
[...]
New Features in Bash
[...]
d. $'...', echo, and printf understand \uXXXX and \UXXXXXXXX escape sequences.
我最近切换到另一个工作机器并在使用西里尔文时遇到问题。我的 Bash 脚本从应用程序获取新消息并使用它们。
然而,这些消息大多是用西里尔字母写的,我得到的结果类似于“\u043f\u0440\u0438\u0432\u0456\u0442”
在我的 运行 Ubuntu 旧系统上,我可以使用 echo -e
[18:18 deimos@nc ~] echo -e "\u043f\u0440\u0438\u0432\u0456\u0442"
привіт
不幸的是,它不适用于 CentOS 6 上的新系统。
[15:21] [server1.nichan.net ~] # echo -e "\u043f\u0440\u0438\u0432\u0456\u0442"
\u043f\u0440\u0438\u0432\u0456\u0442
两个系统都是英文的。 CentOS 是今天刚安装的,所以没有太多内容。到目前为止我在上面安装的唯一东西是 pip 和我的脚本需要的一些 Python 模块,所以可以肯定地说系统是新的。
此外,其他 Unicode 符号似乎也能正常工作。唯一的问题是西里尔文:
[15:21] [server1.nichan.net ~] # echo -e "\xE2\x98\xA0"
☠
如有任何帮助,我们将不胜感激。
UPD:看来我的 Bash 已经过时了。我有 4.1,这个功能至少需要 4.3。我使用本指南更新了 Bash:
wget https://ftp.gnu.org/pub/gnu/bash/bash-4.3.tar.gz
tar xvfz bash-4.3.tar.gz
cd bash-4.3/
./configure
make
ls -la bash
cp -f bash /bin/bash
/bin/bash
\Uxxxx
echo
和 printf
参数中的 Unicode 文字支持已添加到 bash
4.2。
来自change log:
This document details the changes between this version, bash-4.2-alpha, and the previous version, bash-4.1-release.
[...]
New Features in Bash
[...]
d. $'...', echo, and printf understand \uXXXX and \UXXXXXXXX escape sequences.