Set environment variables in Linux

Source: Internet
Author: User
Tags echo command

Setting environment variables and paths in Linux

After the shell runs, many variables are automatically set, which can be modified and added through the command line. The most important variables are path, LD_LIBRARY_PATH, and include.

A string is stored in the Variable. You can use the echo command to view the content of the variable. The usage is as follows:


[hjk41@Redhat hjk41]$ echo $PATH
/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin

Note that there is a "$" in front of the path ". We can see that many directory names are stored in the path, which are separated by colons.

When we execute the command, shell will read the content in path, and then go to each directory in sequence to find the executable file. Once found, it will execute the executable file and return it. For example, if we enter "ls", we can find the executable file named "ls" in/bin. Then shell will execute this file and return

LD_LIBRARY_PATH stores the directory of the dynamic link library, while include is the directory of some header files. These two variables are mainly used in programming.

It is easy to set environment variables. You only need to use the Export command. The usage is as follows:


[hjk41@Redhat hjk41]$ export PATH=$PATH:/home/hjk41/bin
[hjk41@Redhat hjk41]$ echo $PATH
/bin:/usr/local/bin:/usr/bin:/usr/X11R6/bin:/home/hjk41/bin

Note the "$" usage here. Write path refers to the variable path, while write $ PATH refers to the string pointed to by the variable path, that is, "/bin:/usr/local/bin: /usr/bin:/usr/x11r6/bin ". Therefore, the first command sets the PATH variable as a new string. The first part of the string is the old path string, followed by the new string ":/home/hjk41/bin ".

If the name of the variable following the export is not set, shell regards it as a new variable. For example:


 

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.