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
创建并设置变量(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)
翻译自: https://www.poftut.com/set-get-change-bash-environment-variable/
bash 获取环境变量