linux导出日志命令_Linux中的导出命令

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.

到此结束我们有关导出命令的教程。 继续尝试一下,看看魔术! 非常欢迎您提供反馈。

翻译自: https://www.journaldev.com/28251/export-command-linux

linux导出日志命令

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值