linux中设置环境变量_如何在Linux中设置环境变量

本文详细介绍了如何在Linux中设置和删除环境变量,包括创建外壳变量、使用export命令使其成为环境变量,以及使用unset命令删除环境变量。环境变量在控制Shell会话功能方面起着关键作用,理解其设置方法对任何Linux用户都很重要。
摘要由CSDN通过智能技术生成

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
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值