Linux Command env: displays the environment variables of the current user

Source: Internet
Author: User

LinuxEnv IN THE SYSTEMCommandThe current user's environment variables can be displayed, and other commands can be executed under the specified environment variables. The following compares the similarities and differences between the set, env, and export commands: The set command displays the current shell variables, including the current user variables; The env command displays the current user variables; the export command displays the shell variables currently exported as user variables. Each shell has its own unique set variable. This is different from the user variable. The current user variable has nothing to do with what shell you are using, No matter what shell you are using, for example, HOME, SHELL, and other variables, but shell variables are different from shell variables, such as BASH_ARGC and BASH. These variables are only displayed by set and are unique to bash, when an export parameter is not added, it shows which variables are exported as user variables, because a shell variable can be changed to a user variable through export "export.

Common Methods

Format: env

Print the environment variables of the current user.

Format: env-I NAME1 = VALUE1 NAME2 = VALUE2 <command-line>

Use the specified environment variable to execute the command line <command-line>.

Example

Example 1: Compare env, set, and export

The set command prints the most information, including user-defined functions, so that you can see it only when you use more.

[root@www.linuxidc.com ~]# 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[root@www.linuxidc.com ~]# 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="1000"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 22"declare -x SSH_CONNECTION="58.222.185.248 1113 218.23.142.44 22"declare -x SSH_TTY="/dev/pts/6"declare -x TERM="linux"declare -x USER="root"[root@www.linuxidc.com ~]# 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]="25" [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--

Example 2: The env command is used in the source code of the service command.

It can be seen that the service is executing another command, and there are only three environment variables: LANG, PATH, and TERM.

[root@www.linuxidc.com ~]# 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}
[root@www.linuxidc.com ~]#

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.