私のスクリプトは、正しく動作するために特定のロケールでプログラムを実行する必要があるため、そのロケールが利用可能かどうかをチェックしたいと考えています。今のところこのハックを使用しましたが、これを行うより良い方法があると思います。
grep ^ja_JP /etc/locale.gen &>/dev/null || echo >&2 "enable any of the japanese locales first"
man locale
locale -a
利用可能なすべてのロケールをリストすることがわかります。
代わりに次のように言います。
locale -a | grep -q ^ja_JP || echo "enable any of the japanese locales first"
locale -a
利用可能なすべてのロケールを一覧表示する必要があります。
if locale -a | grep ^ja_JP ; then
# locale installed...
else
# locale not installed...
fi