View environment variables under Linux

Source: Internet
Author: User

Original address:

Sometimes when writing makefile, I don't know what some variables are or how to look at them, so I feel it's necessary to write a blog post about environment variables.

If you want to see an environment variable for a name, the command is: echo $ environment variable name , for example:

Echo $ORACLE _home

This is the most basic, below is a little bit deeper, and illustrate

1. Display Environment Variables Home
$echo $HOME

2. Set a new variable
$ export hello= "hello!"

$ echo $HELLO


3. Use the ENV command to display all environment variables

$  Env


4. Use the unset command to clear environment variables
Set sets the value of an environment variable. Clear the value of the environment variable with the unset command. If no value is specified, the value of the variable is set to NULL. Examples are as follows:

$ export test= "TEST ..." #增加一个环境变量TEST

$ env|grep Test #此命令有输入, proving that the environment variable test already exists

Test=test ...

$ unset $TEST #删除环境变量TEST

$ env|grep Test #此命令没有输出, proving that the environment variable test already exists

5. Set read-only variables using the readonly command

If the readonly command is used, the variable cannot be modified or erased. Examples are as follows:

$ export test= "TEST ..." #增加一个环境变量TEST

$ readonly TEST #将环境变量TEST设为只读

$ unset TEST #会发现此变量不能被删除

-bash:unset:test:cannot unset:readonly Variable

$ test= "New" #会发现此也变量不能被修改

-bash:test:readonly variable

Settings for environment variables are located in the/etc/profile file

If you need to add a new environment variable, you can include a subordinate row

Export path= $path:/PATH1:/PATH2:/PAHTN

View environment variables under Linux

Related Article

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: 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.