setenv设置环境变量_setenv命令教程在Linux中添加,删除和更改环境变量

setenv设置环境变量

setenv设置环境变量

Linux and Unix ecosystem mainly used command line based. While working with command line and C Shell we generally need some values to use with commands. Shells provide environment variables for this. This environment variables can be managed with setenv command like add, change and remove.

Linux和Unix生态系统主要使用基于命令行的。 在使用命令行和C Shell时,我们通常需要一些值才能与命令一起使用。 外壳为此提供了环境变量。 可以使用setenv命令(例如添加,更改和删除)来管理此环境变量。

句法 (Syntax)

Syntax of setenv command is very simple we just need to provide the variable name and data

setenv命令的语法非常简单,我们只需要提供变量名称和数据

setenv VARIABLENAME DATA

列出所有环境变量 (List All Environment Variables)

We can use setenv in order to list all environment variables currently defined in C Shell.

我们可以使用setenv来列出C Shell中当前定义的所有环境变量。

$ setenv
List All Environment Variables
List All Environment Variables
列出所有环境变量

添加环境变量(Add Environment Variable)

We will start by creating come environment variable and setting some data to it. We can use lowercase or uppercase letters bu the general usage is uppercase letters. In this case we will create a variable named MYIP and set value 192.168.1.10

我们将首先创建环境变量并为其设置一些数据。 我们可以使用小写或大写字母,一般用法是大写字母。 在这种情况下,我们将创建一个名为MYIP的变量,并将其值设置为192.168.1.10

$ setenv MYIP 192.168.1.10

打印环境变量 (Print Environment Variable)

We can print specific environment variable with echo command. We will provide the environment variable and and prefix with $ . In this example we will print environment variable named MYIP like below.

我们可以使用echo命令打印特定的环境变量。 我们将提供环境变量and并带有$前缀。 在此示例中,我们将如下打印名为MYIP环境变量。

$ echo $MYIP
Print Environment Variable
Print Environment Variable
打印环境变量

将环境变量传递给子外壳或子外壳(Pass Environment Variables To Sub or Child Shell)

Linux process and shell architecture provides the ability to run sub process or shell. Sub process and shell will create a new environment. If we need to use current environment variables in the sub process or shell we just need to use them accordingly. For example in the following example we will print previously defined MYIP in the bash sub-shell.

Linux进程和Shell体系结构提供了运行子进程或Shell的能力。 子进程和shell将创建一个新环境。 如果我们需要在子进程或shell中使用当前环境变量,我们只需要相应地使用它们即可。 例如,在以下示例中,我们将在bash子外壳中打印先前定义的MYIP

$ echo $MYIP
Pass Environment Variables To Sub or Child Shell
Pass Environment Variables To Sub or Child Shell
将环境变量传递给子外壳或子外壳

设置或更新一个环境变量值(Set OR Update One Environment Variable Value)

After assigning a value to a environment variable we may need to update it with new value. We can use set command in order to update current environment variable with a new value. In this example we will update our variable MYIP with 192.168.1.20

将值分配给环境变量后,我们可能需要使用新值对其进行更新。 我们可以使用set命令来用新值更新当前环境变量。 在此示例中,我们将使用192.168.1.20更新变量MYIP。

$ set MYIP=192.168.1.20
Set OR Update One Environment Variable Value 
Set OR Update One Environment Variable Value 
设置或更新一个环境变量值

有用的环境变量(Useful Environment Variables)

There are a lot of default enviroment variables. Here are some of them.

有很多默认环境变量。 这里是其中的一些。

  • USER stores current user name

    USER存储当前用户名

  • PWD current working directory

    PWD当前工作目录

  • SSH_CLIENT the ssh client IP address with source and destination port numbers

    SSH_CLIENT带有源和目标端口号的ssh客户端IP地址

  • SHELL current shell

    SHELL当前外壳

LEARN MORE  Linux Tee Command Tutorial with Examples For Stdout Management
了解更多Linux Tee命令教程,以及有关Stdout管理的示例

翻译自: https://www.poftut.com/setenv-command-tutorial-to-add-delete-and-change-environment-variables-in-linux/

setenv设置环境变量

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值