Environment variable,

Source: Internet
Author: User

Environment variable,
In layman's terms, environment variables are used to tell the computer (actually the operating system) A few directories. These directories store several execution files, such as the/usr/bin directory shown above. Most of the system commands are stored in this directory. When we enter the command mkdir, the system will look up the directories represented by the environment variables from the beginning to the end, which contains the mkdir file, and then execute the mkdir command. In the system, the environment variable is named PATH, and its content can be displayed through the following command (depending on the operating system and configuration, there is a slight difference, but the format is unified ,: split a bunch of paths)

$ echo $PATH/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin
So if we want to make our commands available to the system, we need to add the directory where the commands are located to the environment variable. How can we do this? The path to be added to the environment variable must be a full path. The full path must start with/or start ~ .
# Note that the first PATH does not contain $, and the second PATH has the $ symbol $ export PATH = $ PATH:/home/ct $ echo $ PATH/usr/local/bin: /usr/bin:/usr/local/sbin:/usr/sbin:/home/ct
Therefore, after a new software is installed or a new script is written, the executable program and the directory where the executable script of the software are located, add it to the environment variable. However, execute the export command in the command line to modify the environment variable. The modification is only valid for the current terminal and will be invalid after exiting. To make this operation valid for a long time, we need to write this sentence into a file, and a login server will be automatically read from the file. For common users ~ /. Bash_profile (not ~ /. Bashrc) will be read automatically, so we need to add the export statement to this file.
# This is my ~ /. Bash_profile content, mainly the last line. You can add multiple consecutive paths. If [-f ~ /. Bashrc]; then .~ /. Bashrcfiif [-f ~ /. Bash_aliases]; then .~ /. Bash_aliasesfiexport PATH = $ PATH:/home/ct:/home/bin:/home/soft/bowtie2/bin
As mentioned above, the order of system query commands is from the first directory of environment variables to the last directory. After the first command is run, it is called and executed. If the system has a python Command, we have installed another python (in the/home/ct/anaconda/bin directory). If we want to execute our own python program, you need to write/home/ct/anaconda/bin in front of $ PATH, as shown below:
# Note the order of $ PATH $ export PATH =/home/ct/anaconda/bin: $ PATH
So far, we can use environment variables to simplify the command input process, because if there is no environment variable, we need to run/home/ct/anaconda/bin/python to run the python command.

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.