The env command in the Linux system can display the current user's environment variables and can be used to execute other commands under the specified environment variable. Here's a comparison of the similarities and differences between the set,env and export commands: The SET command displays variables for the current shell, including variables for the current user, and the ENV command displays the current user's variables, and the Export command displays the shell variables that are currently exported as user variables. Each shell has its own unique variable (set), which is different from the user variable, and the current user variable is not related to what shell you are using, no matter what shell you use, such as Home,shell, But Shell's own variable shell is different, such as Bash_argc,bash, and so on, these variables only set will be displayed, is bash-specific, export does not add parameters, show which variables are exported to the user variables, Because a shell's own variable can be exported "export" into a user variable.
Common ways
Format: env
Prints the environment variables for the current user.
Format: env-i name1=value1 name2=value2 <command-line>
Executes command line <command-line> using the specified environment variable.
Using the example
Example one: Compare Env,set and Export
The SET command prints the most information, including custom functions, so that you can see it more clearly using more.
[[email protected] ~]# envhostname=webterm=linuxshell=/bin/bashhistsize=1000ssh_client=58.222.185.248 1113 22ssh_tty=/dev/pts/6ant_home=/opt/apache/apache-ant-1.8.1user=rootls_colors=no=00:fi=00:di=01;34:ln=01;36:pi= 40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01 ; 32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31 :*. zip=01;31:*.z=01;31:*. Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01 ; 35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35:ssh_auth_sock=/tmp/ssh-amfuw25778/agent.25778mail=/var/ spool/mail/rootpath=/usr/kerberos/sbin:/usr/kerberos/bin:/opt/apache/apache-ant-1.8.1/bin:/usr/java/jdk1.6.0_ 20/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bininputrc=/etc/inputrcpwd=/rootjava _home=/usr/java/jdk1.6.0_20lang=zh_cn. Gb18030ssh_askpass=/usr/libexec/openssh/gnome-ssh-askpassshlvl=1home=/rootlogname=rootcvs_rsh=sshssh_connection=58.222.185.248 1113 218.23.142.44 22lessopen=|/usr/bin/ lesspipe.sh%sg_broken_filenames=1_=/bin/env[[email protected] ~]# exportdeclare-x ANT_HOME= "/opt/apache/ apache-ant-1.8.1 "Declare-x cvs_rsh=" ssh "Declare-x g_broken_filenames=" 1 "declare-x histsize=" "Declare-x HOME="/ Root "declare-x hostname=" web "declare-x inputrc="/etc/inputrc "Declare-x java_home="/usr/java/jdk1.6.0_20 "Declare-x Lang= "ZH_CN. GB18030 "Declare-x lessopen=" |/usr/bin/lesspipe.sh%s "Declare-x logname=" root "declare-x ls_colors=" no=00:fi=00:di= 01;34:ln=01;36:pi=40;33:so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*. Exe=01;32:*.com=01;32:*.btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz =01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*. Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01 ; 35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35: "Declare-x mail="/var/spool/mail/root "Declare-x oldpwddeclare-x path="/usr/kerberos/sbin:/usr/kerberos/bin :/opt/apache/apache-ant-1.8.1/bin:/usr/java/jdk1.6.0_20/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/ Sbin:/usr/bin:/root/bin "Declare-x pwd="/root "Declare-x shell="/bin/bash "Declare-x shlvl=" 1 "declare-x SSH_ASKPASS=" /usr/libexec/openssh/gnome-ssh-askpass "Declare-x ssh_auth_sock="/tmp/ssh-amfuw25778/agent.25778 "Declare-x SSH_ client= "58.222.185.248 1113" Declare-x ssh_connection= "58.222.185.248 1113 218.23.142.44" Declare-x ssh_tty= "/dev /PTS/6 "Declare-x term=" Linux "Declare-x user=" root "[[email protected] ~]# Set | Moreant_home=/opt/apache/apache-ant-1.8.1bash=/bin/bashbash_argc= () bash_argv= () BASH_COMPLETION=/etc/bash_ Completionbash_completion_dir=/etc/bash_completion.dbash_lineno= () bash_source= () BASH_VERSINFO= ([0]= "3" [1]= "2" [ 2]= "[3]=" 1 "[4]=" Release "[5]=" I686-redhat-linux-gnu ") bash_version= ' 3.2.25 (1)-release ' Colors=/etc/dir_ Colorscolumns=132cvs_rsh=sshdirstack= () euid=0groups= () g_broken_filenames=1histfile=/root/.bash_historyhistfilesize=1000histsize= 1000home=/roothostname=webhosttype=i686ifs=$ ' \t\n ' Inputrc=/etc/inputrcjava_home=/usr/java/jdk1.6.0_20lang=zh_ CN. Gb18030lessopen= ' |/usr/bin/lesspipe.sh%s ' lines=41logname=rootls_colors= ' no=00:fi=00:di=01;34:ln=01;36:pi=40;33 : so=01;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=01;32:*.cmd=01;32:*.exe=01;32:*.com=01;32:* . btm=01;32:*.bat=01;32:*.sh=01;32:*.csh=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*. zip=01;31:*.z=01;31:*. Z=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tz=01;31:*.rpm=01;31:*.cpio=01;31:*.jpg=01;35:*.gif=01;35:*.bmp=01 ; 35:*.xbm=01;35:*.xpm=01;35:*.png=01;35:*.tif=01;35: ' machtype=i686-redhat-linux-gnumail=/var/spool/mail/ rootmailcheck=60opterr=1optind=1ostype=linux-gnu--more--
The source code for the example two service command is used with the ENV command
You can see that the service is executing a different command, with only three environment variables: LANG, PATH, term.
[[email protected] ~]# grep env/sbin/service
Env-i lang= "$LANG" path= "$PATH" term= "$TERM" "${servicedir}/${service}" status
Env-i lang= "$LANG" path= "$PATH" term= "$TERM" "${servicedir}/${service}" stop
Env-i lang= "$LANG" path= "$PATH" term= "$TERM" "${servicedir}/${service}" start
Env-i lang= "$LANG" path= "$PATH" term= "$TERM" "${servicedir}/${service}" ${options}
[Email protected] ~]#
The Linux command env: Displays the current user's environment variables