使用env命令显示所有的环境变量
-bash-3.00$ env
TERM=vt100
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=123.184.92.69 61281 22
OLDPWD=/home/g/h
SSH_TTY=/dev/pts/6
HISTFILESIZE=1000
USER=snrqtdhuqf
SSH_AUTH_SOCK=/tmp/ssh-Kcyz4912/agent.4912
MAIL=/var/mail//snrqtdhuqf
PATH=/usr/local/bin:/usr/ccs/bin:/opt/gcc/bin:/usr/local/mysql/bin:/usr/sfw/bin:/usr/bin:.
PWD=/home/g/h/snrqtdhuqf
LANG=C
TZ=PRC
SHLVL=1
HOME=/home/g/h/snrqtdhuqf
LOGNAME=snrqtdhuqf
SSH_CONNECTION=123.184.92.69 61281 192.168.1.11 22
_=/usr/local/bin/env
使用set命令显示所有本地定义的shell变量
-bash-3.00$ set
BASH=/bin/bash
BASH_ARGC=()
BASH_ARGV=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="3" [1]="00" [2]="16" [3]="1" [4]="release" [5]="sparc-sun-solaris2.10")
BASH_VERSION='3.00.16(1)-release'
COLUMNS=132
DIRSTACK=()
EUID=33773
GROUPS=()
HISTFILE=/home/g/h/snrqtdhuqf/.bash_history
HISTFILESIZE=1000
HISTSIZE=1000
HOME=/home/g/h/snrqtdhuqf
HOSTNAME=t1000
HOSTTYPE=sparc
IFS=$' /t/n'
LANG=C
LINES=41
LOGNAME=snrqtdhuqf
MACHTYPE=sparc-sun-solaris2.10
MAIL=/var/mail//snrqtdhuqf
MAILCHECK=60
OLDPWD=/home/g/h
OPTERR=1
OPTIND=1
OSTYPE=solaris2.10
PATH=/usr/local/bin:/usr/ccs/bin:/opt/gcc/bin:/usr/local/mysql/bin:/usr/sfw/bin:/usr/bin:.
PIPESTATUS=([0]="0")
PPID=4912
PS1='/s-/v/$ '
PS2='> '
PS4='+ '
PWD=/home/g/h/snrqtdhuqf
SHELL=/bin/bash
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
SHLVL=1
SSH_AUTH_SOCK=/tmp/ssh-Kcyz4912/agent.4912
SSH_CLIENT='123.184.92.69 61281 22'
SSH_CONNECTION='123.184.92.69 61281 192.168.1.11 22'
SSH_TTY=/dev/pts/6
TERM=vt100
TZ=PRC
UID=33773
USER=snrqtdhuqf
_=TERM
echo $HOME 显示环境变量HOME,HOME为环境变量名
-bash-3.00$ echo $HOME
/home/g/h/snrqtdhuqf
export hello="hello" 增加环境变量hello
-bash-3.00$ export hello="hello"
-bash-3.00$ echo $hello
hello
unset hello 删除环境变量hello
-bash-3.00$ unset hello
-bash-3.00$ echo $hello
hello="test" 修改环境变量hello
-bash-3.00$ echo $hello
hello
-bash-3.00$ hello="test"
-bash-3.00$ echo $hello
test
把环境变量hello设置为只读的
readonly hello
-bash-3.00$ export hello="test"
-bash-3.00$ readonlly hello
-bash: readonlly: command not found
-bash-3.00$ readonly hello
-bash-3.00$ hello="hello"
-bash: hello: readonly variable
-bash-3.00$ unset hello
-bash: unset: hello: cannot unset: readonly variable