Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use export Command under linux

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article is about how to use the export command under linux. The editor thought it was very practical, so I shared it with you as a reference. Let's follow the editor and have a look.

The linux export command can be used to set or display environment variables; when executing programs in shell, you can use export to add, modify or delete environment variables for use by subsequent programs. The syntax format is "export [- fnp] [variable name] = [variable setting value]".

1. Windows environment variable

1. Under the Windows system, many software installations need to configure environment variables, such as installing jdk. If you do not configure environment variables and run the javac command in a directory that is not installed by software, you will report that the file cannot be found and similar errors will be reported.

2. So what are environmental variables? To put it simply, it is to specify a directory, and when you run the software, the relevant programs will look for relevant files according to that directory. The most useful function of setting variables for ordinary people is that you don't have to copy some 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. On Linux, if you download and install an application, it is very likely that the prompt "command not found" appears when you type its name. If you go to the installation directory folder every time, it is too cumbersome to find executable files to operate. This involves the setting of the environment variable path, and the setting of Path is also a part of customizing environment variables under Linux.

2. Linux environment variable (export command)

The environment variable startup process:

Function description:

Sets or displays environment variables. (for example, we need to use a command, but the execution file of this command is not in the current directory, so we must specify the directory of the execution file each time we use it. Please, execute export in the code first, which is equivalent to telling the program that the files or things needed to execute something are in these directories.)

Syntax: export [- fnp] [variable name] = [variable set value]

Additional note: when executing a program in shell, shell provides a set of environment variables. Export can add, modify or delete environment variables for use by subsequent programs. The effect of export is limited to this login operation.

Parameters:

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

-n deletes the specified variable. The variable is not actually deleted, but it is not output to the execution environment of subsequent instructions.

-p lists all the environment variables assigned to the program by shell.

When a variable is created, it is not automatically known to the shell process 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 gain access to variables that were originally defined in the script (caller) unless those variables have been explicitly set to available. The export command can be used to pass the values of one or more variables to any subsequent script. -"UNIX tutorial"

In general, when configuring the cross-compilation tool chain, you need to specify the path to the compilation tool, and you need to set the environment variable. For example, when 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. Use the export command directly:

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

To check whether it has been set up, you can use the command export to check:

2. Modify the profile file:

# vi / etc/profile add: export PATH= "$PATH:/opt/au1200_rm/build_tools/bin"

3. Modify the .bashrc file:

# vi / root/.bashrc add: export PATH= "$PATH:/opt/au1200_rm/build_tools/bin"

The latter two methods generally need to log out of the system again to take effect. Finally, you can test them with the echo command:

# echo $PATH

Check to see if the / my_new_path path already exists in the output.

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

If it is not in a standard location, the file name needs to be preceded by a full path. But it's too troublesome to run like this every time, and one way to "once and for all" is to add this path to the environment variable. The command "PATH=$PATH: path" adds this path to the environment variable, but exiting the command line is invalid. To take effect permanently, you need to add this line to the environment variable file. 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 valid only for this user.

"PATH=$PATH: path 1: path 2vv.: path n", which means that the path of the executable file includes the previously set path, as well as all paths from "path 1" to "path n". When the user enters a string of characters and presses enter, shell will look for the corresponding executable file in these paths in turn and give it to the system core for execution. The "$PATH" indicates that the previously 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 system environment variables of class UNIX are separated by colons, not semicolons. In addition, more and more software is installed and 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 according to the order in which the software is installed.

The format is as follows:

# Software name-version number

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

Other environment variables = $other environment variables:.

In "profile" and ".bash _ profile", "#" is an annotation symbol that has no effect except for visual separation.

After the settings are completed, log out and log back in, and the settings will take effect. If you do not log out, executing these statements directly in shell will also work, but the scope is limited to the shell that executed these statements.

After the relevant environment variables take effect, you don't have to go to the executable directory of the software to operate.

Thank you for reading! On the use of export commands under linux to share here, I hope the above content can be of some help to you, so that you can learn more knowledge. If you think the article is good, you can share it and let more people see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report