linux setenv path,setenv(添加或更改环境变量的值)_语法_示例_Unix&Linux命令_uc电脑园移动版官网...

setenv VAR [VALUE]

Arguments

VAR

The name of the variable to be set.

VALUE

The value of the variable, as either a single word or a quoted string.

Description

setenv is a built-in function of the C shell (csh). It is used to define the value of environment variables.

If setenv is given no arguments, it displays all environment variables and their values. If only VAR is specified, it sets an environment variable of that name to an empty (null) value. If both VAR and VALUE are specified, it sets the variable named VAR to the value VALUE. setenv is similar to the set command, which also sets an environment variable's value. However, unlike set, setenv also "exports" this environment variable to any subshells. In this way, it is the equivalent of the bash command export.

For instance, if you are inside the c shell, and you use setenv to set the following variable:

setenv MYVAR myvalue

We can then use the echo command to view the value of that variable:

echo "$MYVAR"

myvalue

Our value, "myvalue", was returned. Now let's run bash as a subshell:

bash

and see if it knows the value of our variable MYVAR:

echo "$MYVAR"

myvalue

As you can see, the value of MYVAR was passed on to bash.

Now, let's see how set is different. Let's go back to csh by exiting the bash subshell:

exit

...and use set to set another environment variable, MYVAR2:

set MYVAR2=myvalue2

(The syntax of set, as you can see, is slightly different. It uses an equals sign to assign a value.) Now let's check the value of MYVAR2:

echo "$MYVAR2"

myvalue2

And now let's go back to bash:

bash

...and check the value of MYVAR2:

echo "$MYVAR2"

This time, no value is reported, because the variable was not "exported" to the subshell. So, when you are using csh, if you want environment variables to remain local to only the current shell, use set. If you want them to carry over to subshells as well, use setenv.

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值