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 in Linux system

2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article mainly shows you "how to use the export command in the Linux system", the content is easy to understand, clear, hope to help you solve your doubts, let the editor lead you to study and learn "how to use the export command in the Linux system" this article.

The Linux export command is used to set or display environment variables, and when a program is executed in shell, shell provides a set of environment variables. Export can add, modify or delete environment variables for use by subsequent programs.

Syntax export [- fnp] [variable name] = [variable setting value] Parameter description:-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.

Case demonstration: * 1. Show all variables of export *

When used without any parameters, the export command displays a list of all export variables in the environment. You should be able to view the name of the variable and its corresponding value.

Linuxmi@linuxmi:~$ export can easily find information about specific variables by using the Linux grep command and the export command. The following command uses a simple example to illustrate this.

Linuxmi@linuxmi:~$ export LINUXMI= "Welcome to linuxmi.com" linuxmi@linuxmi:~$ export | grep-I linuxmi2, the export variable that displays the current Shell

The-p flag of export prints out a list of all exported variables in the current Linux shell. Take a look at the following example to see what this means.

Linuxmi@linuxmi:~$ export-p you can use this command to troubleshoot various configuration problems with running shell sessions.

3. Export variable under Linux

The export command makes it easy to share variables across environments. You can use the export statement to set the value of a variable. The following example demonstrates this.

Linuxmi@linuxmi:~$ export EDITOR=/usr/bin/gedit this sets the path of gedit to the value of the editor variable. You can use grep to confirm this.

Linuxmi@linuxmi:~$ export | Export function under grep-I EDITOR4 and Linux

Developers can use the-f option to export functions. The following example demonstrates this using a simple test function. You can use this method to write custom shell scripts.

Linuxmi@linuxmi:~$ test () {echo "Test Function";} linuxmi@linuxmi:~$ export-f test linuxmi@linuxmi:~$ bash Test Function dircolors: / home/linuxmi/.dircolors: there is no file or directory linuxmi@linuxmi:~$ test Test Function which should display the string "Test Function" in the terminal window. The bash call is used to derive a child process for bash. Otherwise, the test function will not print the text.

5. Configure environment properties

Under the Linux operating system, various environment parameters can be configured using the export command. For example, if you add the following line to the .bashrc file, it will set it to the path of Snap each time the system reboots.

Linuxmi@linuxmi:~$ echo export PATH= "/ snap/bin/lxd:$PATH" > > .bashrc Don't worry if you're not familiar with how the configuration file works inside. Just add a custom export at the end of the file. That way, you can always find them and delete them if you want.

The above is all the contents of the article "how to use export commands in Linux system". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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

Development

Wechat

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

12
Report