What is an environment variable
Environment variables are also called global variables, and the environment variables of the current process are inherited by the process's child processes.
View environment variables
ENV View Environment variables
Set view environment variables and custom variables
Description of some common environment variables
[Email protected] ~]#env//View environment variablesHOSTNAME=BASE //host name term=Linux SHELL=/bin/Bash //use which Shellhistsize=+ //Record the number of history commands ssh_client=192.168.220.1 54798 52113Ssh_tty=/dev/pts/0USER=root //user's name ls_colors=rs=0:d i= on; the:LN= on; $: mh=xx:p i= +; -: so= on; *: Do= on; *: bd= +; -; on: cd= +; -; on: or= +; to; on: mi= on; to;Panax Notoginseng; A:su=Panax Notoginseng; A: sg= -; +: ca= -; A: tw= -; the: ow= the; the: st=Panax Notoginseng; -: ex= on; +:*.Tar= on; to:*. tgz= on; to:*. arj= on; to:*. taz= on; to:*. lzh= on; to:*. lzma= on; to:*. tlz= on; to:*. txz= on; to:*.Zip= on; to:*. z= on; to:*. z= on; to:*. dz= on; to:*. gz= on; to:*. lz= on; to:*. xz= on; to:*. bz2= on; to:*. tbz= on; to:*. tbz2= on; to:*. bz= on; to:*. tz= on; to:*. deb= on; to:*. rpm= on; to:*. jar= on; to:*. rar= on; to:*. ace= on; to:*. zoo= on; to:*. cpio= on; to:*. 7z= on; to:*. rz= on; to:*. jpg= on; *:*. jpeg= on; *:*. gif= on; *:*. bmp= on; *:*. pbm= on; *:*. pgm= on; *:*. ppm= on; *:*. tga= on; *:*. xbm= on; *:*. xpm= on; *:*. tif= on; *:*. tiff= on; *:*. png= on; *:*. svg= on; *:*. svgz= on; *:*. mng= on; *:*. pcx= on; *:*. mov= on; *:*. mpg= on; *:*. mpeg= on; *:*. m2v= on; *:*. mkv= on; *:*. ogm= on; *:*. mp4= on; *:*. m4v= on; *:*. mp4v= on; *:*. vob= on; *:*. qt= on; *:*. nuv= on; *:*. wmv= on; *:*. asf= on; *:*.RM= on; *:*. rmvb= on; *:*. flc= on; *:*. avi= on; *:*. fli= on; *:*. flv= on; *:*. gl= on; *:*. dl= on; *:*. xcf= on; *:*. xwd= on; *:*. yuv= on; *:*. cgm= on; *:*. emf= on; *:*. axv= on; *:*. anx= on; *:*. ogv= on; *:*. ogx= on; *:*. aac= on; $:*. au= on; $:*. flac= on; $:*. mid= on; $:*. midi= on; $:*. mka= on; $:*. mp3= on; $:*. mpc= on; $:*. ogg= on; $:*. ra= on; $:*. wav= on; $:*. axa= on; $:*. oga= on; $:*. spx= on; $:*. xspf= on; $: //Some colors display MAIL=/var/spool/mail/root //The location of the user's mailbox PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/application/mysql/bin:/root/bin //go to which path to find the command PWD=/root //current directory, when you switch directories, you can use the PWD command to remove LANG=en //language Modulepath=/usr/share/modules/modulefiles:/etc/Modulefilesloadedmodules=Histcontrol=IGNOREDUPSSHLVL=1HOME=/root //home directory LOGNAME=Rootcvs_rsh=SSHssh_connection=192.168.220.1 54798 192.168.220.136 52113Moduleshome=/usr/share/Moduleslessopen=|/usr/bin/lesspipe.SH%Sg_broken_filenames=1Module= () {eval '/usr/bin/modulecmd bash $*`}_=/bin/env//Last parameter of last used command (or the command itself)oldpwd=/server/scripts/day1 //exit the last directory, you can use CD-return this directory [[email protected]~]#
Setting environment variables
Export converts a custom variable into an environment variable
[Email protected] ~]# a=Chenyao //Set a variable [[email protected]~]# Bash //Create a child bashhello [[email protected]~]#Echo$a //print A in child bash and find no result because A is only a local variable in the parent bash [[email protected]~]# Exit //exit, return to parent bashExit[[email protected]~]#Echo$a //variable A is still in Chenyao[[email protected]~]# Export a //Use the Export command to set the A variable to an environment variable [[email protected]~]# Bash //Enter child bashhello[[email protected]~]#Echo$a //re-print the variable a,export command works, this time it's working. chenyao[[email Protected]~]# exit //Return to Parent BashExit[[email protected]~]#
To permanently take a custom environment variable
To make the environment variable permanent, just let the change amount be read
Linux start-up process http://www.cnblogs.com/along1226/p/4937520.html
Several files that will be loaded on the boot:
/etc/issue
The information of the system recorded in this folder will be displayed when booting, and should be emptied when optimizing Linux.
/etc/motd
Prompt information when logging in
/etc/profile.d/
This is a directory, which is under the script, the boot will execute these scripts, so we can in this directory, write some script, in the script to declare some variables
/etc/profile
The file, which is used to set the environment variable, the command alias is also generally declared in the file
/etc/rc.local
--------Reference----------------------
After completing the Run Level 3 service startup, if I have other actions I want to complete, for example, I also want to send a mail to a system management account, notify him, the system has just restarted, then, whether should be to create a shell script placed in/ETC/RC. D/i nit.d/inside, and then connected to/etc/rc.d/rc3.d/inside? Oh! Of course you don't! Remember the/etc/rc.d/rc.local you mentioned in the last section? This file will execute the system commands you want to execute. Like Autoexec.ba T and Config.sys in the early DOS era? ^_^
In other words, if I have any work that I want to do at boot time, I will write it directly to/etc/rc.d/rc.local, then the work will be loaded automatically when the boot time! Instead of waiting for us to log into the system to start it! Is it convenient Ah! In general, Brother Bird likes to write his shell script full file name to/etc/rc.d/rc.local, so that the boot will be my shell script executed, it is really good!
--------Reference----------------------
Add an environment variable to make it permanent
Echo ' path= $PATH:/application/mysql/bin/' >>/etc/proflie
Tip: You can only use single quotation marks (output as is), and double quotes will parse the $path.
Environment variables in Linux