5

我的脚本需要运行具有特定语言环境的程序才能正常工作,因此我希望它检查该语言环境是否可用。我现在已经使用了这个 hack,但我认为有更好的方法来做到这一点。

grep ^ja_JP /etc/locale.gen &>/dev/null || echo >&2 "enable any of the japanese locales first"
4

2 回答 2

6

man locale would tell you that locale -a would list all available locales.

Instead say:

locale -a | grep -q ^ja_JP || echo "enable any of the japanese locales first"
于 2013-09-21T08:10:05.993 回答
4

locale -a should list all the available locales:

if locale -a | grep ^ja_JP ; then
    # locale installed...
else
    # locale not installed...
fi
于 2013-09-21T08:09:03.603 回答