printenv,env,set都可以查看环境变量,其中env后面可以接参数,用来查看该环境变量的值。
set会显示某个特定进程设置的所有环境变量,包括局部变量,全局变量和用户自定义的变量。
把局部环境变量导出到全局环境,需要用export命令。
#例如先定义一个自己的变量,
my_var="hello world"
export my_var
#删除环境变量,用unset
unset my_var
当用户登陆centOS时,会启动默认的bash shell,bash首先会执行/etc/profile启动文件中的命令
[wolf@localhost ~]$ cat /etc/profile
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /etc/bashrc
# It's NOT a good idea to change this file unless you know what you
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
# will prevent the need for merging in future updates.
pathmunge () {
case ":${
PATH}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
esac
<