linux导出日志命令
In this guide, we will look at the export command in Linux. Export is a built-in command of the Bash shell. It is used to mark variables and functions to be passed to child processes. Basically, a variable will be included in child process environments without affecting other environments. To get a clearer picture of what we are talking about, let’s dive in and have a look at the export command examples.
在本指南中,我们将研究Linux中的export命令。 导出是Bash shell的内置命令。 它用于标记要传递给子进程的变量和函数。 基本上,变量将包含在子进程环境中,而不会影响其他环境。 为了更清楚地了解我们在说什么,让我们深入研究一下export命令示例。
在Linux中不带任何参数的导出命令 (Export command in Linux without any arguments)
Without any arguments, the command will generate or display all exported variables. Below is an example of the expected output.
不带任何参数的命令将生成或显示所有导出的变量。 以下是预期输出的示例。
$ export
Sample output
样品输出
查看当前shell上的所有导出变量 (Viewing all exported variables on current shell)
If you wish to view all exported variables on the current shell, use the -p
flag as shown in the example
如果希望查看当前shell上的所有导出变量,请使用-p
标志,如示例所示
$ export -p
Sample output
样品输出
使用导出功能 (Using export with functions)
Suppose you have a function and you wish to export it, how do you go about it? In this case , the -f
flag is used. In this example, we are exporting the function name ()
.
假设您有一个函数并且希望导出它,该如何处理? 在这种情况下,将使用-f
标志。 在此示例中,我们导出函数name ()
。
First, call the function
首先,调用函数
$ name () { echo "Hello world"; }
Then export it using the -f
flag
然后使用-f
标志将其导出
$ export -f name
Next, invoke bash shell
接下来,调用bash shell
$ bash
Finally, call the function
最后,调用函数
$ name
Output
输出量
Hello World
You can also assign a value before exporting a function as shown
您还可以在导出函数之前分配一个值,如下所示
$ export name[=value]
For example, you can define a variable before exporting it as shown
例如,您可以在导出变量之前定义一个变量,如下所示
$ student=Divya
In the above example, the variable ‘student’ has been assigned the value ‘Divya’
在上面的示例中,变量“ student”被分配了值“ Divya”
To export the variable run
导出变量运行
$ export students
You can use the printenv
command to verify the contents of the variable as shown
您可以使用printenv
命令来验证变量的内容,如下所示
$ printenv students
Check the output below of the commands we have just executed
检查下面我们刚刚执行的命令的输出
Output
输出量
The above can be achieved in 2 simple steps by declaring and exporting the variable in one line as shown
可以通过两个简单的步骤就可以实现上述目标,方法是在一行中声明并导出变量,如图所示
$ export student=Divya
To display the variable run
显示变量运行
$ printenv student
Output
输出量
This concludes our tutorial about export command. Go ahead and give it a try and see the magic! Your feedback is most welcome.
到此结束我们有关导出命令的教程。 继续尝试一下,看看魔术! 非常欢迎您提供反馈。
linux导出日志命令