|
Variable types of Linux
Press lifetime variable to divide, Linux variables can be divided into two categories:
1 permanent: the need to modify the configuration files, variables permanent.
Temporary 2: Use the export command to declare the variable fail in the closed shell.
Three ways to set variables
1 variables in the / etc / profile file for all users [entry into force of (permanent)]
Increase in variable file / etc / profile file using the VI, the variable will be effective for all users to Linux, and is "permanent."
For example: Edit / etc / profile file add the CLASSPATH variable
# Vi / etc / profile
. Export CLASSPATH = / JAVA_HOME / lib; $ JAVA_HOME / jre / lib
NOTE: After modifying the file in order to take effect immediately even run # source / etc / profile or only the next time the user re-enter into force.
2 increase variable in .bash_profile in the user directory under [the entry into force of a single user (permanent)]
Increase with VI in the .bash_profile file in the user directory variable, the amount of change is only valid on the current user, and is "permanent."
For example: .bash_profile edit guok user directory (/ home / guok) under
$ Vi /home/guok/.bash.profile
Add the following:
. Export CLASSPATH = / JAVA_HOME / lib; $ JAVA_HOME / jre / lib
NOTE: After modifying the file in order to take effect immediately will run for $ source /home/guok/.bash_profile otherwise only the next time the user re-enter into force.
3 run directly export command to define variables [only for the current shell (BASH) effective (temporary)]
Use [export variable name = variable value] to define variables directly in the shell command line,
The only variable in the current shell (BASH) or a sub-shell (BASH) below is valid,
Close up of shell variables also fails, you do not have this variable and then open a new shell, if you need to use also need to be redefined.
Check environment variables
1 Use the echo command to view a single environment variable. E.g:
echo $ PATH
2 Use env to see all the environment variables. E.g:
env
3 Use set to see all the local environment variables defined.
Use unset to delete the specified environment variable
set can set the value of an environment variable. Clear the environment variable with the unset command. If you do not specify a value, the value of the variable will be set to NULL. Examples are as follows:
$ Export TEST = "Test ..." # add an environment variable TEST
$ Env | grep TEST # this command input, proof environment variable TEST already exists
TEST = Test ...
unset TEST # delete the environment variable TEST
$ Env | grep TEST # this command no output, proven environment variable TEST have been deleted
Common environment variables
PATH to determine the shell which directories to find commands or programs
HOME The current user's home directory
HISTSIZE history records
LOGNAME current user's login name
HOSTNAME refers to the name of the host
SHELL Current User Shell type
LANGUGE language-related environment variables, multi-language environment variables can be modified
MAIL current user's mail store directory
PS1 primary prompt for the root user is #, for the average user is $ |
|
|
|