SHELL script - variable

Environment Variables                    

Environment variable is to run in the "environment" context, in this context can be referenced. For example, a common cd, ls command, etc. Strictly speaking, you should use absolute paths such as / bin / ls to perform, due to the / bin directory to the PATH environment variable, the system will look for themselves whether there is a path in the PATH command.

Environment variables commonly used capital letters. Common environmental variables HOSTNAME, SHELL, HISTSIZE, USER, PATH, PWD, LANG, HOME, LOGNAME. Represent the current host name, SHELL path that is bash's type, history save how many records, the current user name, automatic search path, the current directory, language used (to change the variables to temporarily modify language), the current user's home directory, the current logged-on user.

Use env can view or export the current user's environment variables.

[root@localhost ~]# env
HOSTNAME=localhost.localdomain
TERM=vt100
SHELL=/bin/bash
HISTSIZE=1000
SSH_CLIENT=192.168.1.5 50651 22
QTDIR=/usr/lib64/qt-3.3
QTINC=/usr/lib64/qt-3.3/include
SSH_TTY=/dev/pts/0
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=01;05;37;41:su=37;41 : sg = 30 ; 43 : = 30 ; 41 : tw = 30 ; 42 : ow = 34 ; 42 : st = 37 ; 44 : ex = 01 ; 32 : *. Tar = 01 ; 31 : *. Tgz = 01 ; 31 : *. Arj = 01 ; 31 : *. Taz = 01 ; 31 : *. Lzh = 01 ; 31 : *. Lzma = 01 ; 31 : *. Tlz = 01 ; 31 : *. Txz =01 ; 31 *. Zip = 01 ; 31 *. Z = 01 ; 31 *. Z = 01 ; 31 *. Dz = 01 ; 31 :. * G = 01 ; 31 *. L = 01 ; 31 *. X = 01 ; 31 *. Bz2 = 01 ; 31 *. Tbz = 01 ; 31 *. Tbz2 = 01 ; 31 *. Bz = 01 ; 31 *. T = 01 ; 31 *. Deb = 01 ;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=01;36:*.au=01;36:*.flac=01;36:*.mid=01;36:*.midi=01;36:*.mka=01;36:*.mp3=01;36:*.mpc=01;36:*.ogg=01;36:*.ra=01;36:*.wav=01;36:*.axa=01;36:*.oga=01;36:*.spx=01;36:*.xspf=01;36:
MAIL=/var/spool/mail/root
PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
PWD=/root
LANG=zh_CN.UTF-8
HISTCONTROL=ignoredups
SHLVL=1
HOME=/root
LOGNAME=root
QTLIB=/usr/lib64/qt-3.3/lib
CVS_RSH=ssh
SSH_CONNECTION=192.168.1.5 50651 192.168.1.213 22
LESSOPEN=||/usr/bin/lesspipe.sh %s
G_BROKEN_FILENAMES=1
_=/bin/env

Using the echo value of the variable may be output.

[root@localhost ~]# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

For example, in the PATH environment variable to add a new directory / usr / local / mysql / bin.

[root@localhost ~]# PATH=/usr/local/mysql/bin:$PATH
[root@localhost ~]# echo $PATH
/usr/local/mysql/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

Here can be seen the first two did not use $ PATH, the second use. When the variable operation itself, not using the $, when the operating variable values, use $ .

Ordinary variables                            

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/liujunjun/p/11997307.html