快捷搜索:   nginx

Linux系统中如何修改某用户语言环境变量

在所管理的服务器上,有的可以在终端里面输入汉字,有的不行,会显示乱码。比较其相对应的环境变量。发现关于语言的环境变量不一样。在网上搜索了大量的资料,没有找到解决的方法。看了鸟哥书中相关的部分才找到解决的方法。(网络上的信息量太大,有时会浪费大量的时间,还是没有找到自己想要的)
 
  把掌握的方法和道理记录下来。
 
  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 "(^|:)$1($|:)" ; then
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$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


 
  终端乱码问题得到解决。
顶(0)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论