sh-# export
export CONSOLE="/dev/console"
export HOME="/"
export LD_LIBRARY_PATH="......."
export OLDPWD
export PATH="/bin:/usr/bin:/sbin:/usrbin"
export PREVLEVEL="N"
export PWD="/"
export RUNLEVEL="4"
export SHLVL="3"
export TERM="vt100"
export TERMINFO="/usr/share/terminfo"
sh-#
export命令是shell builtin命令。
sh-# type export
export is a shell builtin
使用export命令设置的环境变量只会在当前系统中生效,如果想让其永久生效,必须在/etc/profile、~/.bash_profile或~/.bashrc等配置文件中进行设置
1. 如何查看指定的环境变量的值?
sh-# echo $PATH
/bin:/usr/bin:/sbin:/usrbin
2. 如果修改环境变量的值?
sh-# export PATH=$PATH:./
sh-# echo $PATH
/bin:/usr/bin:/sbin:/usrbin:./
3. 使用export命令可以直接定义一个新的环境变量,并且这个环境变量的值可以继承到子进程中。
sh-# export NEW_VAR=xulin
sh-# echo $NEW_VAR
xulin
sh-#
sh-# export
export CONSOLE="/dev/console"
export HOME="/"
export NEW_VAR="xulin"
export OLDPWD="://basic/"
export PATH="/bin:/usr/bin:/sbin:/usrbin:./"
export PREVLEVEL="N"
export PWD="/"
export RUNLEVEL="4"
export SHLVL="3"
export TERM="vt100"
export TERMINFO="/usr/share/terminfo"
sh-#
4. 如何删除一个环境变量?
使用-n选项可以临时使一个指定的环境变量在当前运行的系统中失效,除非重新启动系统才能恢复。
sh-# export -n NEW_VAR
sh-# echo $NEW_VAR
xulin
sh-#
sh-# export NEW_VAR=xulin
sh-# echo $NEW_VAR
xulin
sh-#
sh-# export
export CONSOLE="/dev/console"
export HOME="/"
export OLDPWD="://basic/"
export PATH="/bin:/usr/bin:/sbin:/usrbin:./"
export PREVLEVEL="N"
export PWD="/"
export RUNLEVEL="4"
export SHLVL="3"
export TERM="vt100"
export TERMINFO="/usr/share/terminfo"
sh-#
通过下面的验证,果真如此。
sh-# export | grep NEW_VAR
sh-#
sh-# set | grep NEW_VAR
NEW_VAR=xulin
sh-#