1

我在 ~/bin/ 中有以下脚本,以便覆盖默认命令gnome-terminal

#!/usr/bin/env bash
XDG_CONFIG_HOME=~/.config/darkthemesettings /usr/bin/gnome-terminal

我试图使该XDG_CONFIG_HOME变量仅被 gnome-terminal 看到,但在出现的终端中,如果我运行任何其他程序,该变量也会在该程序中设置。echo $XDG_CONFIG_HOME从终端运行会给出 /home//.config/darkthemesettings

我知道,如果一个人在不使用的情况下设置了一个环境变量export,那么该变量只能在设置它的脚本中使用,而不是在任何子进程中。我不正确吗?我怎样才能在这里实现我想要的?谢谢

4

2 回答 2

2

You can use env to unset the variable for the command run inside the terminal, like this:

XDG_CONFIG_HOME=~/.config/darkthemesettings gnome-terminal -x env -u XDG_CONFIG_HOME bash

The assignment XDG_CONFIG_HOME=~/.config/darkthemesettings before the command gnome-terminal sets the variable for the terminal. The terminal will run the arguments after the -x option as shell command. That shell command bash is prefixed by env -u XDG_CONFIG_HOME which unsets the variable in the environment for running bash.

于 2014-09-25T14:03:22.063 回答
1

你的理解是不正确的。没有export它们就是 bash 变量。export将它们“提升”为环境变量。

在运行 shell 之前,您需要让 gnome-terminal 运行一个取消设置变量的脚本。

于 2012-04-27T20:08:01.063 回答