Linux environment variables (a)

  
The first time to learn lliux knowledge of environmental variables is not resolved, special time spent a morning summed up, can be said to be comprehensive! If you have more detailed insights, you may wish to inform!

custom environment variables Shell environment variables are closely related and, after user login system launched a Shell. For Linux it is generally bash, but you can also reset or switch to another shell. Environment variables are set by the shell command, and the set environment variables can be used by all programs running by the current user. For the bash shell program, you can access the corresponding environment variable by variable name, and set the environment variable through export. The following is illustrated by several examples.

1. Display environment variable HOME

$ echo $HOME

/home/terry

2. Set a new environment variable WELCOME

$ export WELCOME="Hello!"

$ echo $WELCOME

Hello!

3. Use the env command to display all environment variables

$ env

HOSTNAME=terry.mykms.org

PVM_RSH=/usr/bin/rsh

SHELL=/bin/bash

TERM= Xterm

HISTSIZE=1000

...

4. Use the set command to display all locally defined shell variables

$ set

BASH=/bin/bash

BASH_VERSINFO=([0]="2"[1]="05b"[2]="0"[3]="1"[4]="release "[5]="i386-redhat-linux-gnu")

BASH_VERSION='2.05b.0(1)-release'

COLORS=/etc/DIR_COLORS.xterm

COLUMNS=80

DIRSTACK=()

DISPLAY=:0.0

...

5. Use the unset command to clear the environment. The variable

set can set the value of an environment variable. Clear the value of the environment variable with the unset command. If no value is specified, the variable value will be set to NULL. Here is an example:

$ export TEST="Test..." #Add an environment variable TEST

$ env| Grep TEST #This command has input to prove that the environment variable TEST already exists

TEST=Test...

$ unset $TEST #Delete environment variable TEST

$ env | Grep TEST #This command has no output, which proves that the environment variable TEST already exists.

6. Use the readonly command to set the read-only variable

If the readonly command is used, the variable cannot be modified or Cleared. Here is an example:

$ export TEST="Test..." #Add an environment variable TEST

$ readonly TEST #Set the environment variable TEST to read-only

$ Unset TEST # will find that this variable cannot be deleted

-bash: unset: TEST: cannot unset: readonly variable

$ TEST="New" # will find that this variable can not be modified < BR>
-bash: TEST: readonly variableetc/profile is valid for the entire system.
Make sure you are using bash

Add
export LANG=zh_CN.GBK
export LC_ALL= zh_CN.GBK
export XMODIFIERS=@im=Chinput
The configuration of csh may be
setenv LANG zh_CN.GBK
setenv LC_ALL zh_CN.GBK
setenv XMODIFIERS @im=Chinput
< BR> You can also create ~/.bash_profile file, set
related files in the file and .bash_logout .bash_login
For example, my .bash_logout specifies
clear
Every exit is automatically cleared Screen

How to set the shell environment variable?
Shell
Setting
Add
Remove
Show current value
Annotations
shNAME=value1
export NAMENAME=value2:$NAMEunset NAMEset(int Ernal) or env(exported) If you need the child process to see the environment variable, you need to use export kshNAME=value1
export NAMENAME=value2:$NAMEunset NAMEset(internal) or env(exported) if you need the child process also see The environment variable needs to use export cshsetenv NAME value1setenv NAME value2:$NAMEunsetenv NAMEset does not need to use export bashNAME=value1NAME=value2:$NAMEunset NAMEset or env If you need the child process to see the environment variable, you need to use export
Copyright © Windows knowledge All Rights Reserved