linux The export command can be used to set or display environment variables; when executing a program in the shell, you can use export to add, modify or delete environment variables for subsequent execution of the program. The syntax format is "export [-fnp][Variable name]=[Variable setting value]".
Related recommendations: "Linux Video Tutorial"
1. Under Windows systems, many software installations require configuring environment variables, such as installing jdk. If you do not configure environment variables and run the javac command in a non-software installation directory, it will report that it cannot be found. to file, similar error.
2. So what are environment variables? Simply put, it means specifying a directory. When running the software, the relevant program will search for relevant files according to the directory. The most practical function of setting variables for ordinary people is: there is no need to copy certain dll files to the system directory, and the system variable path is a series of paths for the system to search for dll files
## 3 . Under Linux system, if you download and install an application, it is very likely that a "command not found" prompt will appear when typing its name. If you go to the installation directory folder every time, it will be too cumbersome to find the executable file to operate. This involves the setting of the environment variable path, and the setting of Path is also an integral part of customizing environment variables under Linux.
Environment variable startup process:
Function description:
Set or display environment variables. (For example, we want to use a command, but the executable file of this command is not in the current directory, so we must specify the directory of the executable file every time we use it. Please, execute export first in the code. This is equivalent to telling the program to execute so-and-so. When you need something, the required files or stuff are in these directories)
Syntax: export [-fnp][variable name]=[variable Setting value]
Supplementary instructions:When executing a program in the shell, the shell will provide a set of environment variables. Export can add, modify or delete environment variables for use by subsequent programs. The effect of export is only limited to this login operation.
Parameters:
-f represents the function name in [variable name].
-n Delete the specified variable. The variable is not actually deleted, it is just not output to the execution environment of subsequent instructions.
-p Lists all environment variables assigned to the program by the shell.
When a variable is created, it is not automatically known to shell processes created after it. The command export can pass the value of the variable to the subsequent shell. When a shell script is called and executed, it does not automatically gain access to variables defined in the original script (the caller) unless these variables have been explicitly made available. The export command can be used to pass the value of one or more variables to any subsequent script. ----"UNIX Tutorial"
Generally speaking, when configuring the cross-compilation tool chain, you need to specify the path of the compilation tool. At this time, you need to set the environment variable. For example, my mips-linux-gcc compiler is in the "/opt/au1200_rm /build_tools/bin" directory, and build_tools is my compilation tool. There are three ways to set environment variables:
1. Directly use the export command:
#export PATH=$PATH:/opt/au1200_rm/build_tools/bin
to check whether it has been set up. You can use the export command to check:
2. Modify the profile file:
#vi /etc/profile 在里面加入: export PATH="$PATH:/opt/au1200_rm/build_tools/bin"
3. Modify the .bashrc file:
# vi /root/.bashrc 在里面加入: export PATH="$PATH:/opt/au1200_rm/build_tools/bin"
The latter two methods generally require logging out of the system again to take effect. Finally, you can test it through the echo command:
# echo $PATH
See if the path /my_new_path is already in the output.
"/bin", "/sbin", "/usr/bin", "/usr/sbin", "/usr/local/bin" and other paths are already in the system environment variable. If the executable file is in these standard locations, enter the file name and parameters (if parameters are required) of the software executable file on the terminal command line, and press Enter.
If it is not in the standard location, the full path needs to be added in front of the file name. However, running like this every time is too troublesome. A "once and for all" method is to add this path to the environment variable. The command "PATH=$PATH:path" can add this path to the environment variable, but it will be invalid after exiting the command line. To take effect permanently, you need to add this line to the environment variable file. There are two files available: "/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. Only valid for this user.
"PATH=$PATH:path1:path2:...:pathn" means that the path of the executable file includes the originally set path, 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 sequentially find the corresponding executable files in these paths and hand them over to the system core for execution. That “$PATH” means that the originally set path is still valid, so be careful not to miss it. Some software may have environment variables other than "PATH" that need to be added, but the method is the same, and you also need to pay attention to "$".
Note that unlike DOS/Window, path names in UNIX system environment variables are separated by colons, not semicolons. In addition, as more software is installed, more and more environment variables are added. In order to avoid confusion, it is recommended that all statements be added at the end of the file and added in the order in which the software is installed.
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, and writing it here has no effect except visual separation.
After the settings are completed, log out and log in again, and the settings will take effect. If you do not log out, executing these statements directly in the shell will also take effect, but the scope is limited to the shell that executed these statements.
After the relevant environment variables take effect, you no longer need to go to the executable file directory of the software to operate.
#For more programming-related knowledge, please visit:
Programming Video Course! !
The above is the detailed content of How to use the export command under linux?. For more information, please follow other related articles on the PHP Chinese website!