mio
mio

Reputation: 101

Check if a specific locale is enabled in bash

My script needs to run a program with a specific locale to work correctly, so I want it to check whether that locale is available. I've used this hack for now, but I think there's a better way to do this.

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

Upvotes: 6

Views: 4561

Answers (2)

devnull
devnull

Reputation: 123508

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"

Upvotes: 8

choroba
choroba

Reputation: 241908

locale -a should list all the available locales:

if locale -a | grep ^ja_JP ; then
    # locale installed...
else
    # locale not installed...
fi

Upvotes: 5

Related Questions