在Ubuntu中设置环境变量时出错

时间:2022-04-27 22:43:45

I tried to add a path variable in /etc/environment on Ubuntu.

我试图在Ubuntu上的/ etc / environment中添加一个路径变量。

JAVA_HOME=/usr/local/java/jdk1.8.0_31
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
PATH=$PATH:$JAVA_HOME/bin

After I quit the shell and login again, it seems the $PATH has been messed up. Many common commands like ls, vim don't work anymore. I run echo $PATH and the output is:

在我退出shell并再次登录后,似乎$ PATH已经搞砸了。许多常见的命令,如ls,vim不再起作用。我运行echo $ PATH,输出是:

$PATH:$JAVA_HOME/bin

Apparently, the "$" is not parsed correctly here. I wanna keep using "$" as it provides certain flexibility. Is there a work-around for this issue?

显然,这里没有正确解析“$”。我想继续使用“$”,因为它提供了一定的灵活性。这个问题有解决办法吗?

1 个解决方案

#1


0  

As mentioned here, "Variable expansion does not work in /etc/environment".

如此处所述,“变量扩展在/ etc / environment中不起作用”。

You would have to generate /etc/environment with a script to get the effect that you want.

您必须使用脚本生成/ etc / environment以获得所需的效果。

#1


0  

As mentioned here, "Variable expansion does not work in /etc/environment".

如此处所述,“变量扩展在/ etc / environment中不起作用”。

You would have to generate /etc/environment with a script to get the effect that you want.

您必须使用脚本生成/ etc / environment以获得所需的效果。