How to set and view Linux environment variables

Source: Internet
Author: User
How to set and view Linux environment variables 1. display the environment variable HOME $ echo $ homewww.2cto.com/home/redbooks2.set a new environment variable hello#exporthello&quot=hello! & Quot; $ echo $ HELLOHello !... How to set and view Linux environment variables 1. display the environment variable HOME $ echo $ HOME www.2cto.com/home/redbooks 2. set a new environment variable hello $ export HELLO = "Hello! "$ Echo $ HELLO Hello! 3. use the env command to display all environment variables $ env HOSTNAME = redbooks.safe.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. you can use the unset command to clear the environment variable set to set the value of an environment variable. Run the unset command to clear the environment variable values. If no value is specified,
The variable value is set to NULL. Example: $ export TEST = "Test... "# Add an environment variable TEST $ env | grep TEST # This command is input to prove that the environment variable TEST already has TEST = Test... www.2cto.com $ unset $ TEST # Delete the environment variable TEST $ env | grep TEST # This command is not output, it proves that the environment variable TEST already exists 6. if the readonly command is used to set the read-only variable, the variable cannot be modified or cleared. Example: $ export TEST = "Test... "# Add an environment variable TEST $ readonly TEST # set the environment variable TEST as read-only $ unset TEST # you will find that this variable cannot be deleted-bash: unset: TEST: cannot unset: readonly variable $ TEST = "New" # this variable cannot be modified-bash: TEST: readonly variable environment variable settings are located in the/etc/profile File. if you need to add a new environment variable, you can add the subordinate row export path = $ path:/path1:/path2:/pahtN variable ----------------------------------------------------------------------------------------------------------- ------------ 1. Linux variable types are divided by the variable life cycle. Linux variables can be divided into two categories: 1.1 Permanent: the configuration file needs to be modified, and the variable takes effect permanently. 1.2 temporary: Use the export command to declare the variable. the variable becomes invalid when the shell is closed. 2. three ways to set variables 2.1 add variables to the/etc/profile file [effective for all users (permanent)] use VI to add variables to the file/etc/profile file, this variable will be valid for all users in Linux and "permanent ". For example, edit the/etc/profile file and add the CLASSPATH variable # vi/etc/profile export CLASSPATH =. /JAVA_HOME/lib; $ JAVA_HOME/jre/lib note: to change the file to take effect immediately, run # source/etc/profile. Otherwise, it will only take effect the next time you re-enter this user. 2.2. add the variable "effective for a single user (permanent)" to the bash_profile file and use VI in the user directory. add a variable to the bash_profile file. the variable quantity is valid only for the current user and is "permanent ". For example, edit. bash_profile $ vi/home/guok /. bash. add the following content to profile: export CLASSPATH =. /JAVA_HOME/lib; $ JAVA_HOME/jre/lib note: to change the file to take effect immediately, run $ source/home/guok /. bash_profile
This takes effect the next time you enter this user. 2.3 run the export command directly to define the variable [only valid for the current shell (BASH) (temporary)] use the [export variable name = variable value] to define the variable under the shell command line, this variable is only available in the current shell
(BASH) or its sub-shell (BASH) is valid. if the shell is closed, the variable will become invalid. when the new shell is opened, no
This variable needs to be redefined if needed. 3. View environment variables 3.1 use the echo command to view a single environment variable. For example, echo $ PATH 3.2 uses env to view all environment variables. For example, env www.2cto.com 3.3 uses set to view all locally defined environment variables. Unset can delete specified environment variables. 4. the commonly used environment variable PATH determines the directories to which shell will look for commands or programs HOME current user's HOME directory HISTSIZE number of historical records LOGNAME current user's login name HOSTNAME refers to the host name SHELL current user Shell type LANGUGE language-related environment variables, in multiple languages, you can modify this environment variable to MAIL the current user's MAIL storage directory PS1 BASIC prompt, for root users is #, for common users is $
 

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.