Ubuntu 22.04.2 LTS
$ locale
$ locale -a
$ sudo nano /etc/locale.gen
$ sudo locale-gen
$ sudo nano /etc/default/locale
$ source /etc/default/locale
$ sudo sh {SCRIPT_FILE}.sh list
$ sudo sh {SCRIPT_FILE}.sh en_US.UTF-8
#/bin/bash
locale_gem_file="/etc/locale.gen"
locale_default_file="/etc/default/locale"
if [ -z "$1" ]
then
echo "Please enter an option"
echo "list"
echo "encoding-name"
exit 1
fi
if [ "$1" = "list" ]
then
if [ ! -f $locale_gem_file ]; then
echo "The file $locale_gem_file does not exist."
exit 1
else
sed '1,6d; 7,$ {/^[[:space:]]/d;}' $locale_gem_file
exit 1
fi
fi
if ! grep -q "$1" "$locale_gem_file"
then
echo "Please enter the correct encoding."
exit 1
fi
if grep -q "$1" "$locale_gem_file"
then
sed -i "/$1/s/^#[[:space:]]*//" "$locale_gem_file"
sudo locale-gen
locale -a
fi
if [ -f "$locale_default_file" ]
then
sed -i "s/^LANG=.*/LANG="$1"/" $locale_default_file
sed -i "s/^LC_ALL=.*/LC_ALL="$1"/" $locale_default_file
. $locale_default_file
locale
bash
fi