Linux Bash Shell导出教程和示例

Bash is a shell and a simple programming shell too. There are a lot of variables built-in or externally specified. If a variable is specified externally making this variable system-wide available is a problem. The export command makes variables available system-wide by propagating to the subshells. An exported variable would not be available to the parent processes. This means previously spawned or created process will not get exported variable. Syntax of export is like below there is two way to export some variable.

Bash也是一个shell和一个简单的编程shell。 有很多内置或外部指定的变量。 如果在外部指定了变量,则使该变量在系统范围内可用是一个问题。 通过传播到子shell,export命令使变量在系统范围内可用。 导出的变量对父进程将不可用。 这意味着先前生成或创建的进程将不会获得导出的变量。 导出的语法如下所示,有两种导出某些变量的方法。

直接出口 (Directly Export)

We can export the newly created variable with the following syntax by using export keyword.

我们可以使用export关键字以以下语法导出新创建的变量。

export VAR

In this case, we export all readily defined variables to the subshells.

在这种情况下,我们将所有容易定义的变量导出到子shell。

$ myfw=10.0.0.1
$ export myfw
Directly Export
Directly Export
直接出口

定义后导出(Export After Defining)

We can use the following syntax in order to export all readily defined bash variables.

我们可以使用以下语法来导出所有易于定义的bash变量。

export VAR=VALUE

In this model, the variable is just defined before exported. After variable definition variable exported to the system-wide.

在此模型中,变量仅在导出之前定义。 变量定义后将变量导出到系统范围内。

$ export httpserver=192.168.1.10
Export After Defining
Export After Defining
定义后导出

列出导出的变量(List Exported Variables)

It can be listed exported variables with the -p parameter.

可以使用-p列出导出的变量 参数。

$ export -p
List Exported Variables
List Exported Variables
列出导出的变量

We can see from the output that there are a lot of exported variables to the bash shell. Some of them are HOME, LANG ,LOGNAME etc.

从输出中我们可以看到,有很多导出到bash shell的变量。 其中一些是HOMELANGLOGNAME等。

LEARN MORE  What Is Command Line and Command Prompt In Windows Operating System?
了解更多信息Windows操作系统中的命令行和命令提示符是什么?

翻译自: https://www.poftut.com/linux-bash-shell-export-tutorial-with-examples/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值