我的脚本需要运行具有特定语言环境的程序才能正常工作,因此我希望它检查该语言环境是否可用。我现在已经使用了这个 hack,但我认为有更好的方法来做到这一点。
grep ^ja_JP /etc/locale.gen &>/dev/null || echo >&2 "enable any of the japanese locales first"
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"
locale -a
should list all the available locales:
if locale -a | grep ^ja_JP ; then
# locale installed...
else
# locale not installed...
fi