Linux command Details (i) Export command

Source: Internet
Author: User
Tags echo command

One, Windows environment variables

1, under the Windows system, many software installations need to configure environment variables, such as installing the JDK, if you do not configure environment variables, run the JAVAC command in a directory other than the software installation, you will report a similar error that the file cannot be found.

2. What are environment variables? To put it simply, it is to specify a directory, when running the software, the relevant program will follow the directory to find the relevant files. The most practical function of setting variables is that you don't have to copy some DLL files into the system directory, and path is a system variable that is a series of paths for the system to search for DLL files.

3, under the Linux system, if you download and install the application, it is possible to type its name when the "command not found" prompt content. If you go to the installation directory folder every time, it is too cumbersome to find an executable file to work with. This involves setting the environment variable path, and the path setting is also a component of customizing the environment variable under Linux.

ii. Linux Environment variables (Export command)

environment variable startup process:

Function Description:

Sets or displays environment variables. (for example, we want to use a command, but the execution of this command is not in the current directory, so we must specify the directory to execute the file each time we use, trouble, in the code to execute the export, this is equivalent to tell the program, execute a certain thing, the required files or something in these directories)

Syntax: Export [-fnp][variable name]=[variable setting value]

Additional Note: when executing a program in the shell, the shell provides a set of environment variables. Export can add, modify, or delete environment variables for use by subsequent executing programs. The effect of export only extends to the operation of this landing.

Parameters

-F represents the function name in [variable name].

-n Deletes the specified variable. The variables are not actually deleted, but are not exported to the execution environment of the subsequent directives.

-p lists all the environment variables that the shell assigns to the program.

When a variable is created, it is not automatically known to the shell process that was created after it. The command export can pass the value of the variable to the following shell. When a shell script is called and executed, it does not automatically get access to the variables defined in the script (the caller) unless the variables have been explicitly set to available.     The export command can be used to pass the value of one or more variables to any subsequent script. ----"UNIX Tutorial"

In general, you need to specify the path of the compilation tool when configuring the cross-compilation tool chain, and you need to set the environment variables. For example, my MIPS-LINUX-GCC compiler in the "/opt/au1200_rm/build_tools/bin" directory, Build_tools is my compilation tool, there are three ways to set the environment variables:

1. Direct with export command:

#export path= $PATH:/opt/au1200_rm/build_tools/bin

To see if it is already set up, use the command export to view:

2, modify the profile file:

#vi/etc/Profileadded: Export PATH="$PATH:/opt/au1200_rm/build_tools/bin"

3. Modify the. bashrc file:

# vi/root/. BASHRC Add in: Export PATH="$PATH:/opt/au1200_rm/build_tools/bin" 

The latter two methods generally require a re-logoff system to take effect, and finally can be tested by the echo command:
# echo $PATH


See if the output is already/my_new_path this path.

"/bin", "/sbin", "/usr/bin", "/usr/sbin", "/usr/local/bin" and other paths are already in the system environment variables, if the executable file in these standard locations, in the terminal command line enter the software executable file name and parameters ( If parameters are required), enter.

If not in a standard location, the file name needs to be preceded by a full path. But it's too much trouble to run like this every time, a "once and for all" approach is to add this path to the environment variable. The command "path= $PATH: Path" can add this path to an environment variable, but exiting the command line will fail . This line needs to be added to the environment variable file in order to be permanently active. There are two files to choose from: "/etc/profile" and ". Bash_profile" in the user's home directory, "/etc/profile" is valid for all users in the system, and ". Bash_profile" in the user's home directory is only valid for this user.   

"Path= $PATH: Path 1: Path 2: ...: path n", which means that the path to the executable file includes the path originally set, and also includes all paths from "Path 1" to "Path N". When the user enters a string of characters and presses ENTER, the shell will find the corresponding executable file in these paths in turn and hand it over to the system core execution. The "$PATH" means that the path originally set is still valid, so be careful not to miss out. Some software may also have an environment variable of type "PATH" that needs to be added, but the method is the same, and you also need to be aware of "$".

Note that, unlike Dos/window, the path names in the UNIX class system environment variables are separated by colons, not semicolons. In addition, the more loaded the software, the more environment variables, in order to avoid confusion, it is recommended that all statements are added at the end of the file, in the software installation order.

The format is as follows ():

# Software Name-version number

Path= $PATH: Path 1: Path 2: ...: path n

Other environment variables =$ other environment variables: ...

In "Profile" and ". Bash_profile", "#" is a comment symbol that is written here without any effect except visual separation.

Setup is complete, log off and log back in, and the settings take effect. If you do not log off, executing these statements directly in the shell can also take effect, but the scope is limited to the shell that executes the statements.

Once the relevant environment variable is in effect, you don't have to run into the software's executable directory.

Linux command Details (i) Export 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.