In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
In this article, the editor introduces in detail how to use the Linux export command in detail, the content is detailed, the steps are clear, and the details are handled properly. I hope this article "how to use the Linux export command correctly" can help you solve your doubts.
Export sets export properties for shell variables or functions.
Summary export [- fn] [name [= word]]. The main purpose of export-p is to define one or more variables and set export properties.
Modify the values of one or more variables and set the export properties.
Delete the export properties of one or more variables.
Displays all variables that have exported properties.
Add export properties for one or more defined functions.
Removes the export properties of one or more functions.
Displays all functions that have exported properties.
Option-f: point to the function. -n: deletes the export attribute of the variable. -p: displays all variables that have export properties. -pf: displays all functions that have export properties. -nf: deletes the export attribute of the function. The option after it is not valid. Parameter name (optional): variable name or defined function name.
Value (optional): value of the variable.
The return value export returns true unless you provide an illegal option or illegal name.
Example # shows all variables that have export attributes. # export-p # export # displays all functions that have export properties. # export-pf # first delete the variable name to be demonstrated # unset a b # define the variable while adding the export attribute export a bread3 # of course you can also define and then add the export attribute bread3 export b # modify the value of the variable with the exported attribute export axi5 baud 7 # of course you can also directly assign a value to modify axi5 Export 7 # delete the export attribute of the variable export-n a b # first delete the function name unset func_1 func_2 # to be demonstrated create the function function func_1 () {echo '123arguments;} function func_2 () {echo' 890' } # add export attribute export-f func_1 func_2 # delete function export attribute export-fn a b # add environment variable (JAVA) to `~ / .bashrc` PATH=/usr/local/jdk1.7.0/bin:$PATH # add current location to dynamic library environment variable export LD_LIBRARY_PATH=$ (pwd): ${LD_LIBRARY_PATH} incorrect usage add export attribute to undefined function.
Delete exported attributes on functions / variables that do not have exported attributes.
Use the option after--.
Q&AQ: what's the use of setting export properties for variables or functions? A: they become environment variables and can be accessed in scripts, especially when required by child processes called in scripts.
Q: if I write a script that modifies the value of an existing environment variable, will execution take effect on the current terminal? Will it affect the terminals opened before and after? A: only scripts called through source will take effect, and you can check the source command for more information; other ways are just executed in the child shell. The previous one will not be affected, unless you modify the script loaded when the terminal is started, such as ~ / .bashrc.
Q: my script file calls the functions and variables defined in ~ / .bashrc. Why can't you use these functions and variables when calling the script through sh in a newly opened terminal or directly running the script that the current user has permission to execute?
A: please add export their statements to the ~ / .bashrc file.
Q: can arrays and associative arrays also set export properties? A: yes (if your bash supports them), but there are some problems.
Q: why do I start with declare when I look at the exported properties of a variable or function? A: because declare can also set the export properties of variables or functions, see the declare command for details.
Note that this command is a bash built-in command. For help, please see the help command.
The knowledge points refer to the shell execution environment in section 3.7.3 of the info bash or bash online documentation, which involves variables and functions as follows
Shell parameters that are set by variable assignment or with set or inherited from the shell's parent in the environment
Shell functions defined during execution or inherited from the shell's parent in the environment
So what does the parameter in the first sentence have to do with the variable? In the first paragraph of section 3.4, it is mentioned:
A variable is a parameter denoted by a name.
Variables are parameters with names.
So the child shell does inherit the variable or function with the exported attribute in the parent shell.
After reading this, the article "how to use the Linux export command correctly" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself to understand it. If you want to know more about related articles, 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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.