![/etc/profile に export utf8 を追加しても機能しない](https://rvso.com/image/1555355/%2Fetc%2Fprofile%20%E3%81%AB%20export%20utf8%20%E3%82%92%E8%BF%BD%E5%8A%A0%E3%81%97%E3%81%A6%E3%82%82%E6%A9%9F%E8%83%BD%E3%81%97%E3%81%AA%E3%81%84.png)
debian:stretch のロケールを utf8 に設定しようとしています。次に使用する Docker イメージをビルドします。Dockerfile の一部:
# Set locale
RUN sed --in-place '/en_US.UTF-8/s/^# //' /etc/locale.gen && \
locale-gen && \
# Set system locale (add line)
echo "export LANG=en_US.UTF-8" >> /etc/profile && \
# Set system timezone (add line)
echo "export TZ=UTC" >> /etc/profile
私が構築したイメージを使用する Gitlab ジョブ:
$ cat /etc/profile
# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).
if [ "`id -u`" -eq 0 ]; then
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
else
PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
fi
export PATH
if [ "${PS1-}" ]; then
if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
# The file bash.bashrc already sets the default PS1.
# PS1='\h:\w\$ '
if [ -f /etc/bash.bashrc ]; then
. /etc/bash.bashrc
fi
else
if [ "`id -u`" -eq 0 ]; then
PS1='# '
else
PS1='$ '
fi
fi
fi
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fi
export LANG=en_US.UTF-8
export TZ=UTC
$ locale
LANG=
LANGUAGE=
LC_CTYPE="POSIX"
LC_NUMERIC="POSIX"
LC_TIME="POSIX"
LC_COLLATE="POSIX"
LC_MONETARY="POSIX"
LC_MESSAGES="POSIX"
LC_PAPER="POSIX"
LC_NAME="POSIX"
LC_ADDRESS="POSIX"
LC_TELEPHONE="POSIX"
LC_MEASUREMENT="POSIX"
LC_IDENTIFICATION="POSIX"
LC_ALL=
なぜ変更されないのか分かりません。/etc/profile
ファイルを読み取っていないようです。
答え1
マニュアルページを引用するにはbash(1)
:
bash が対話型ログイン シェルとして、または オプション付きの非対話型シェルとして呼び出されると、そのファイルが存在する場合は、
--login
まずそのファイルからコマンドを読み取って実行します。そのファイルを読み取った後、bash は、、、 をこの順序で 探し 、存在し読み取り可能な最初のファイルからコマンドを読み取って実行します。 この動作を禁止するには、シェルの起動時に オプションを使用できます。/etc/profile
~/.bash_profile
~/.bash_login
~/.profile
--noprofile
<…>
ログイン シェルではない対話型シェルが起動されると、これらのファイルが存在する場合、bash は および からコマンドを読み取って実行します
/etc/bash.bashrc
。~/.bashrc
これは、 オプションを使用して抑制できます--norc
。fileオプションは、bash におよび--rcfile
ではなく file からコマンドを読み取って実行するように強制します 。/etc/bash.bashrc
~/.bashrc