如何删除导出的环境变量?
在安装 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
unset
是您要查找的命令。unset
is the command you're looking for.在 Bash 中创建和删除环境变量的演练:
测试 DUALCASE 变量是否存在(空输出):
不存在,因此创建变量并将其导出:
检查它是否存在:
输出:
它就在那里。因此,摆脱它:
检查它是否仍然存在(空输出):
DUALCASE 导出的环境变量被删除。
帮助清除本地和环境变量的额外命令:
登录时将所有本地变量恢复为默认值:
输出:
exec bash
命令清除了所有局部变量,但没有清除环境变量。登录时将所有环境变量恢复为默认值:
输出:
env -i bash
命令在登录时将所有环境变量清除为默认值。Walkthrough of creating and deleting an environment variable in Bash:
Test if the DUALCASE variable exists (empty output):
It does not, so create the variable and export it:
Check if it is there:
Output:
It is there. So get rid of it:
Check if it's still there (empty output):
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:
Output:
exec bash
command cleared all the local variables, but not environment variables.Unset all environment variables back to default on login:
Output:
env -i bash
command cleared all the environment variables to default on login.最初的问题没有提到如何设置变量,但是:
在C shell (csh/tcsh) 设置环境变量有两种方法:
set x = "something"
setenv x "something"
行为上的差异是用设置的变量setenv 命令会自动导出到子 shell,而使用 set 设置的变量则不会。
要取消使用 set 设置的变量集,请使用
要取消使用 setenv 设置的变量集,请使用
注意:在上述所有内容中,我假设变量名称是“x”。
学分:
TCSH / CSH:set 与 setenv 命令差异
set、unset、setenv、unsetenv、export — 构建的 Shell 环境变量-in 函数
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:
set x = "something"
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
To unset a variable set with setenv, use
Note: in all the above, I assume that the variable name is 'x'.
Credits:
TCSH / CSH: set vs setenv Command Differences
set, unset, setenv, unsetenv, export — Shell Environment Variable Built-in Functions
在 Linux 和 macOS 上,您可以使用命令
unset
删除环境变量。永久删除该变量,
在 Linux 中
您可以编辑 shell 配置文件,例如
/etc/profile.d
.bashrc 或.bash_profile
> 目录并删除导出变量的行。.bashrc 文件:
然后,搜索export
GNUPLOT_DRIVER_DIR
行并将其删除。然后保存文件。在 Windows 中,
使用 setx 命令删除环境变量。
您可以在以下链接中找到有关环境变量以及如何管理它们的更多信息:
Linux:https://www.cyberciti.biz/faq/set-environment-variable-linux/
Windows:https://www.computerhope.com/issues/ch000549.htm
On Linux and macOS, you can use the command
unset
to remove an environment variable.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:
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.You can find more information about environment variables and how to manage them in the following links:
Linux: https://www.cyberciti.biz/faq/set-environment-variable-linux/
Windows: https://www.computerhope.com/issues/ch000549.htm
这也可能有效。
This may also work.
正如上面的答案中提到的,如果您使用
export
设置变量,则unset GNUPLOT_DRIVER_DIR
应该可以工作。如果您已将其永久设置在~/.bashrc
或~/.zshrc
中,那么只需从那里删除它即可。As mentioned in the above answers,
unset GNUPLOT_DRIVER_DIR
should work if you have usedexport
to set the variable. If you have set it permanently in~/.bashrc
or~/.zshrc
then simply removing it from there will work.Linux
首先找到哪个脚本文件定义了该变量并将其添加到环境中。
在文件夹 /etc 中查找类似 profile 的文件,bash.bashrc,.bashrc 文件,.bashrc_login 等。
并在用户的主目录中查找类似名称的文件。
如果它不在其中任何一个中,则它可能位于某个已安装软件包的脚本文件中。例如,包 SDKMAN(用于管理备用 SDK 版本)创建一个名为 DERBY_HOME 的变量。要查找创建它的脚本文件,请将以下搜索命令应用于 /etc 文件夹:
这应该会产生一些输出,例如:
需要单独的文件 jdk.csh C-shell 环境(如果用户已默认)。
一旦找到,只需导航到包含脚本文件的文件夹,在本例中为 /etc/profile.d/,然后编辑文件(具有管理员权限),删除变量分配和保存:
当然,在这种情况下设置环境变量的包正在使用中,所以我保留了它。
但是,如果该包未被使用并且环境变量对启动过程造成了沉重负担,那么应该将其删除。
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:
This should produce some output like:
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:
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.