linux中设置环境变量
Wondering how to set environment variables in Linux? This is exactly what we’ll be doing in this tutorial. Operating systems make use of environment variables to define system properties for the runtime environment.
想知道如何在Linux中设置环境变量? 这正是我们在本教程中将要做的。 操作系统利用环境变量来定义运行时环境的系统属性。
Through this tutorial, we will help you understand how environment variables work. Further, we will see how to set environment variables in Linux or reset existing environment variables as per our needs.
通过本教程,我们将帮助您了解环境变量的工作方式。 此外,我们将了解如何根据需要在Linux中设置环境变量或重置现有环境变量。
了解环境变量 (Understanding Environment Variables)
When we start a session on our server through the shell, it has to create an environment for us. This is a mandatory step for us to interact with the server through the shell.
当我们通过外壳在服务器上启动会话时,它必须为我们创建一个环境。 这是我们通过外壳与服务器交互所必须执行的步骤。
Environment variables are special variables that are available to all commands and processes on a system. These variables have the following formats.
环境变量是特殊变量,可用于系统上的所有命令和进程。 这些变量具有以下格式。
ENVAR=value
ENVAR="Another value"
ENVAR=value_1:value_2
- All variable names are case-sensitive. We provide all environment variables with an uppercase name by convention. 所有变量名称均区分大小写。 根据约定,我们为所有环境变量提供一个大写名称。
- When assigning a value to our variable, we make sure there is no space around the assignment operator (=). 在为变量赋值时,请确保赋值运算符(=)周围没有空格。
- If we need to assign multiple values to a single environment variable, we make use of a colon (:) to separate the different values. 如果需要为单个环境变量分配多个值,则可以使用冒号(:)分隔不同的值。
列出Linux中的现有环境变量 (List existing Environment Variables in Linux)
If we want to see the environment variables for our current session, we use the following command.
如果要查看当前会话的环境变量,请使用以下命令。
printenv