如何删除导出的环境变量?

发布于 2024-11-27 07:06:19 字数 230 浏览 3 评论 0原文

在安装 gnuplot 之前,我设置了环境变量 GNUPLOT_DRIVER_DIR = /home/gnuplot/build/源代码。在安装过程中,出现了问题。

我想删除 GNUPLOT_DRIVER_DIR 环境变量。我怎样才能实现它?

Before installing gnuplot, I set the environment variable GNUPLOT_DRIVER_DIR = /home/gnuplot/build/src. During the installation, something went wrong.

I want to remove the GNUPLOT_DRIVER_DIR environment variable. How can I achieve it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

天暗了我发光 2024-12-04 07:06:19

unset 是您要查找的命令。

unset GNUPLOT_DRIVER_DIR

unset is the command you're looking for.

unset GNUPLOT_DRIVER_DIR
迷你仙 2024-12-04 07:06:19

在 Bash 中创建和删除环境变量的演练:

测试 DUALCASE 变量是否存在(空输出):

env | grep DUALCASE

不存在,因此创建变量并将其导出:

DUALCASE=1
export DUALCASE

检查它是否存在:

env | grep DUALCASE

输出:

双大小写=1

它就在那里。因此,摆脱它:

unset DUALCASE

检查它是否仍然存在(空输出):

env | grep DUALCASE

DUALCASE 导出的环境变量被删除。

帮助清除本地和环境变量的额外命令:

登录时将所有本地变量恢复为默认值:

CAN="chuck norris"
set | grep CAN

输出:

CAN='查克·诺里斯'

env | grep CAN # Empty output

exec bash
set | grep CAN
env | grep CAN # Empty output

exec bash 命令清除了所有局部变量,但没有清除环境变量。

登录时将所有环境变量恢复为默认值:

export DOGE="so wow"
env | grep DOGE

输出:

DOGE=哇哦

env -i bash
env | grep DOGE # Empty output

env -i bash 命令在登录时将所有环境变量清除为默认值。

Walkthrough of creating and deleting an environment variable in Bash:

Test if the DUALCASE variable exists (empty output):

env | grep DUALCASE

It does not, so create the variable and export it:

DUALCASE=1
export DUALCASE

Check if it is there:

env | grep DUALCASE

Output:

DUALCASE=1

It is there. So get rid of it:

unset DUALCASE

Check if it's still there (empty output):

env | grep DUALCASE

The DUALCASE exported environment variable is deleted.

Extra commands to help clear your local and environment variables:

Unset all local variables back to default on login:

CAN="chuck norris"
set | grep CAN

Output:

CAN='chuck norris'

env | grep CAN # Empty output

exec bash
set | grep CAN
env | grep CAN # Empty output

exec bash command cleared all the local variables, but not environment variables.

Unset all environment variables back to default on login:

export DOGE="so wow"
env | grep DOGE

Output:

DOGE=so wow

env -i bash
env | grep DOGE # Empty output

env -i bash command cleared all the environment variables to default on login.

妥活 2024-12-04 07:06:19

最初的问题没有提到如何设置变量,但是:

C shell (csh/tcsh) 设置环境变量有两种方法:

  1. set x = "something"
  2. setenv x "something"

行为上的差异是用设置的变量setenv 命令会自动导出到子 shell,而使用 set 设置的变量则不会。

要取消使用 set 设置的变量集,请使用

unset x

要取消使用 setenv 设置的变量集,请使用

unsetenv x

注意:在上述所有内容中,我假设变量名称是“x”。

学分:

The original question doesn't mention how the variable was set, but:

In C shell (csh/tcsh) there are two ways to set an environment variable:

  1. set x = "something"
  2. setenv x "something"

The difference in the behaviour is that variables set with the setenv command are automatically exported to a subshell while variables set with set aren't.

To unset a variable set with set, use

unset x

To unset a variable set with setenv, use

unsetenv x

Note: in all the above, I assume that the variable name is 'x'.

Credits:

可爱咩 2024-12-04 07:06:19

在 Linux 和 macOS 上,您可以使用命令 unset 删除环境变量。

unset GNUPLOT_DRIVER_DIR

永久删除该变量,

在 Linux 中

您可以编辑 shell 配置文件,例如 /etc/profile.d.bashrc 或 .bash_profile > 目录并删除导出变量的行。

.bashrc 文件:

nano ~/.bashrc

然后,搜索export GNUPLOT_DRIVER_DIR 行并将其删除。然后保存文件。

在 Windows 中,

使用 setx 命令删除环境变量。

setx GNUPLOT_DRIVER_DIR ""

您可以在以下链接中找到有关环境变量以及如何管理它们的更多信息:

On Linux and macOS, you can use the command unset to remove an environment variable.

unset GNUPLOT_DRIVER_DIR

Remove the variable permanently,

In Linux

You can edit your shell profile file, such as .bashrc or .bash_profile in the /etc/profile.d directory and remove the line that exports the variable.

.bashrc file:

nano ~/.bashrc

Then, search for the line export GNUPLOT_DRIVER_DIR and delete it. Then save the file.

In Windows

use the setx command to delete an environment variable.

setx GNUPLOT_DRIVER_DIR ""

You can find more information about environment variables and how to manage them in the following links:

┾廆蒐ゝ 2024-12-04 07:06:19

这也可能有效。

export GNUPLOT_DRIVER_DIR=

This may also work.

export GNUPLOT_DRIVER_DIR=
薄凉少年不暖心 2024-12-04 07:06:19

正如上面的答案中提到的,如果您使用 export 设置变量,则 unset GNUPLOT_DRIVER_DIR 应该可以工作。如果您已将其永久设置在 ~/.bashrc~/.zshrc 中,那么只需从那里删除它即可。

As mentioned in the above answers, unset GNUPLOT_DRIVER_DIR should work if you have used export to set the variable. If you have set it permanently in ~/.bashrc or ~/.zshrc then simply removing it from there will work.

灵芸 2024-12-04 07:06:19

Linux

首先找到哪个脚本文件定义了该变量并将其添加到环境中。

在文件夹 /etc 中查找类似 profile 的文件bash.bashrc.bashrc 文件.bashrc_login 等。

并在用户的主目录中查找类似名称的文件。

如果它不在其中任何一个中,则它可能位于某个已安装软件包的脚本文件中。例如,包 SDKMAN(用于管理备用 SDK 版本)创建一个名为 DERBY_HOME 的变量。要查找创建它的脚本文件,请将以下搜索命令应用于 /etc 文件夹:

sudo egrep -lir THE_VAR_NAME /etc

这应该会产生一些输出,例如:

/etc/profile.d/jdk.sh
/etc/profile.d/jdk.csh

需要单独的文件 jdk.csh C-shell 环境(如果用户已默认)。

一旦找到,只需导航到包含脚本文件的文件夹,在本例中为 /etc/profile.d/,然后编辑文件(具有管理员权限),删除变量分配和保存:

cd /etc/profile.d/

sudo gedit jdk.sh

sudo gedit jdk.sh

当然,在这种情况下设置环境变量的包正在使用中,所以我保留了它。

但是,如果该包未被使用并且环境变量对启动过程造成了沉重负担,那么应该将其删除。

Windows

使用此 YouTube 视频中所示的流程。

Linux

First find which script file defines and adds the variable to the environment.

Look in folder /etc for files like profile, bash.bashrc, .bashrc file, .bashrc_login, etc.

And look for similarly named files in the user's home directory.

If it's not in any of those, it's likely that it's in some script file that was part of an installed package. For example, the package SDKMAN (for managing alternate SDK versions) creates a variable called DERBY_HOME. To find the script file creating it, apply the following search command to the /etc folder:

sudo egrep -lir THE_VAR_NAME /etc

This should produce some output like:

/etc/profile.d/jdk.sh
/etc/profile.d/jdk.csh

The separate file jdk.csh is needed for the C-shell environment if users have defaulted to it.

Once found it is simply a matter of navigating to the folder containing the script files, in this case here /etc/profile.d/ and then editing the files (with admin permission), removing the variable assignments and saving:

cd /etc/profile.d/

sudo gedit jdk.sh

sudo gedit jdk.sh

Of course, in this case the package setting the environment variable is in use, so I kept it.

But if the package were not in use and the environment variables dead weight to the startup process, then it should be deleted.

Windows

Use the process shown in this YouTube video.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文