有些命令支持多种语言,如果脚本没有做兼容,很可以导致结果错误,例如:
readelf -h hello.o | grep Type
在本地语言区是 enUS.UTF-8 时有结果返回,但是,语言区设置为 zhCN.UTF-8 没有任何结果。
对比一下,两种语言时,readelf 的输出。
[yz@localhost c]$ echo $LANG en_US.UTF-8 [yz@localhost c]$ LANG='en_US.UTF-8' ; readelf -h hello.o ELF Header: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: REL (Relocatable file) [yz@localhost c]$ echo $LANG zh_CN.UTF-8 [yz@localhost c]$ LANG='zh_CN.UTF-8' ; readelf -h hello.o ELF 头: Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 类别: ELF64 数据: 2 补码,小端序 (little endian) Version: 1 (current) OS/ABI: UNIX - System V ABI 版本: 0 类型: REL (可重定位文件)
因此,如果脚本不兼容多种语言,则最好强制设置 LANG 环境变量。
echo $LANG
local
yum groupinstall chinese-support
LANG="zh_CN.UTF-8"
vi /etc/sysconfig/i18n 填写 LANG="zh_CN.UTF-8"