將匯出 utf8 新增至 /etc/profile 不起作用

將匯出 utf8 新增至 /etc/profile 不起作用

嘗試將 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 作為互動式登入 shell 或帶有該選項的非互動式 shell 被呼叫時--login,它首先從檔案中讀取並執行命令/etc/profile(如果該檔案存在)。
讀取該檔案後,它會按順序查找 ~/.bash_profile~/.bash_login、 和~/.profile,並從第一個存在且可讀的檔案中讀取並執行命令。--noprofile當 shell 啟動時可以使用該 選項來禁止此行為。

<...>

當啟動非登入 shell 的互動式 shell 時,bash 會讀取並執行來自/etc/bash.bashrc 和 的 命令~/.bashrc(如果這些檔案存在)。這可以透過使用該--norc選項來抑制。 file選項將強制 bash 從 file 而不是和 --rcfile讀取並執行命令 。/etc/bash.bashrc~/.bashrc

相關內容