在所管理的服務器上,有的可以在終端裡面輸入漢字,有的不行,會顯示亂碼。比較其相對應的環境變量。發現關於語言的環境變量不一樣。在網上搜索了大量的資料,沒有找到解決的方法。看了鳥哥書中相關的部分才找到解決的方法。(網絡上的信息量太大,有時會浪費大量的時間,還是沒有找到自己想要的)
把掌握的方法和道理記錄下來。
bash shell的配置文件:
/etc/profile用於設定幾個重要變量,例如PATH,USER,MAIL,HOSTNAME,HISTSIZE, UMASK等。
-bash-3.00# more /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
pathmunge () {
if ! echo $PATH | /bin/egrep -q "(^|:){GetProperty(Content)}($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:{GetProperty(Content)}
else
PATH={GetProperty(Content)}:$PATH
fi
fi
}
# Path manipulation
if [ `id -u` = 0 ]; then
pathmunge /sbin
pathmunge /usr/sbin
pathmunge /usr/local/sbin
fi
pathmunge /usr/X11R6/bin after
# No core files by default
ulimit -S -c 0 > /dev/null 2>&1
USER="`id -un`"
LOGNAME=$USER
MAIL="/var/spool/mail/$USER"
HOSTNAME=`/bin/hostname`
HISTSIZE=1000
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
INPUTRC=/etc/inputrc
fi
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
. $i
fi
done
unset i
unset pathmunge
/etc/bashrc :用於規劃umask,同時規劃提示符的內容。
-bash-3.00# more /etc/bashrc
# /etc/bashrc
# System wide functions and aliases
# Environment stuff goes in /etc/profile
# by default, we want this to get set.
# Even for non-interactive, non-login shells.
if [ "`id -gn`" = "`id -un`" -a `id -u` -gt 99 ]; then
umask 002
else
umask 022
fi
# are we an interactive shell?
if [ "$PS1" ]; then
case $TERM in
xterm*)
if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
else
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
fi
;;
screen)
if [ -e /etc/sysconfig/bash-prompt-screen ]; then
PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
else
PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\033\\"'
fi
;;
*)
[ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prom
pt-default
;;
esac
# Turn on checkwinsize
shopt -s checkwinsize
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
fi
if ! shopt -q login_shell ; then # We're not a login shell
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
. $i
fi
done
unset i
fi
# vim:ts=4:sw=4
alias ls="ls --color"
設定後,需要注銷再登錄才能起作用。
個人設定值:
~/.bash_profile個人路徑與環境變量的文件名稱。
-bash-3.00# more .bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
unset USERNAME
LANG=zh_CN.gbk
~/.bashrc:重要的個人設定文件
-bash-3.00# more .bashrc
# .bashrc
# User specific aliases and functions
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
~/.bash_history:這個文件記錄曾經使用過的命令。
修改個人用戶的語言環境變量可以修改。bashrc或者。bash_profile.
-bash-3.00# env
HOSTNAME=example
.............
LANG=en_US.UTF-8
修改後:
QUOTE:
-bash-3.00# env
HOSTNAME=example
.............
LANG=en_US.UTF-8
LANG=zh_CN.gbk
終端亂碼問題得到解決