Original address: http://blog.chinaunix.net/uid-25124785-id-77098.html
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
/home/ljj
2. Set a new variable
$ export hello= "hello!"
$ echo $HELLO
Hello!
3. Use the ENV command to display all environment variables
$ Env
Orbit_socketdir=/tmp/orbit-ljj
ssh_agent_pid=1525
Term=xterm
Shell=/bin/bash
xdg_session_cookie=5e42e49d41b7b05ff090ea4a4ce0a37d-1294464361.122772-796576665
windowid=58845346
oldpwd=/usr/src/linux-source-2.6.32
Gnome_keyring_control=/tmp/keyring-vncvzp
Gtk_modules=canberra-gtk-module
User=ljj
...
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