bash 获取环境变量_如何设置,获取和更改Bash环境变量?

bash 获取环境变量

bash 获取环境变量

Bash shell is used for a lot of things in Linux systems. Most of the applications run with bash. Bash is a shell but provides an environment that can be used to programming. Variables are core of the programming. Bash provides variables too. There are default variables as well as user defined variables.

Bash shell在Linux系统中用于很多事情。 大多数应用程序使用bash运行。 Bash是一个外壳程序,但提供了可用于编程的环境。 变量是编程的核心。 Bash也提供变量。 有默认变量和用户定义的变量。

获取现有的Bash环境变量 (Get Existing Bash Environment Variables)

Bash provides a lot of variables by default. Those variables can be used to get information about shell, system, running applications etc. We can list all ready created environment variables with the env command like below.

Bash默认提供很多变量。 这些变量可用于获取有关Shell,系统,正在运行的应用程序等的信息。我们可以使用如下env命令列出所有已创建的环境变量。

$ env
Get Existing Bash Environment Variables
Get Existing Bash Environment Variables
获取现有的Bash环境变量

创建并设置变量(Create and Set Variable)

Creating and setting a variable in bash is very easy. We just need to specify the variable name and set the value with equal sign like below. In this example we will create a variable named count and set its value integer .

在bash中创建和设置变量非常容易。 我们只需要指定变量名并使用等号设置值即可,如下所示。 在此示例中,我们将创建一个名为count的变量并将其值设置为整数

$ count=0

获取变量 (Get Variable)

Getting a variable values is very easy we just need to add $ to the start of the variable name. In this example we will print the count variable value.

获取变量值非常容易,我们只需要在变量名的开头添加$即可。 在此示例中,我们将打印count变量值。

$ echo $count 
0

更改变量值 (Change Variable Value)

We can change all ready created variables value. It is the same way of creating a variables. So we will just provide the variable name the the value. In this example we will set variable count to the 1.

我们可以更改所有现成的变量值。 这与创建变量的方法相同。 因此,我们将只提供变量名称和值。 在此示例中,我们将变量count设置为1

$ count=1 
$ echo $count 
1

如何设置,获取和更改Bash环境变量? 信息移植 (How To Set, Get and Change Bash Environment Variable? Infografic)

How To Set, Get and Change Bash Environment Variable? Infografic
How To Set, Get and Change Bash Environment Variable? Infografic
如何设置,获取和更改Bash环境变量? 信息移植

翻译自: https://www.poftut.com/set-get-change-bash-environment-variable/

bash 获取环境变量

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值