bash Eclipse 不使用 .bashrc 中设置的路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18099272/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 06:10:13  来源:igfitidea点击:

Eclipse doesn't use the path set in .bashrc

linuxeclipsebashubuntu

提问by JREN

whenever I run eclipse from the shortcut I am unable to correctly build some of my projects because the PATHvariable that I configured in .bashrcdoesn't get used.

每当我从快捷方式运行 eclipse 时,我都无法正确构建我的一些项目,因为PATH我配置的变量.bashrc没有得到使用。

When I run eclipse from my terminal, I can build all my projects perfectly fine because it's running through the correct shell.

当我从终端运行 eclipse 时,我可以完美地构建我的所有项目,因为它通过正确的 shell 运行。

The problem is that I want to use the PATHvariable from my .bashrcwithout permanently having a terminal open. I tried this before, but every day I accidentally close the terminal that's running eclipse by accident and lose all my unsaved code.

问题是我想在没有永久打开终端的情况下使用PATH我的变量.bashrc。我以前试过这个,但每天我不小心关闭了运行 eclipse 的终端并丢失了我所有未保存的代码。

Can anyone help me?

谁能帮我?

采纳答案by Kent

I can think of two options for this problem:

对于这个问题,我可以想到两种选择:

  • write a small script, export those vars or source your .bashrc before you start your eclipse.
  • define those variables in /etc/environment. then they are not user-scope any more.
  • 在开始 eclipse 之前,编写一个小脚本,导出这些变量或获取 .bashrc 的源。
  • 在 /etc/environment 中定义这些变量。那么它们就不再是用户范围了。

I prefer the 1st option.

我更喜欢第一个选项。

回答by SpamBot

  1. Edit /usr/share/applications/eclipse.desktop with write privileges, i.e. sudo gedit /usr/share/applications/eclipse.desktop

  2. Change the setting Exec=/usr/bin/eclipseto Exec=bash -ic "/usr/bin/eclipse"and save

  1. 使用写权限编辑/usr/share/applications/eclipse.desktop,即 sudo gedit /usr/share/applications/eclipse.desktop

  2. 将设置更改Exec=/usr/bin/eclipseExec=bash -ic "/usr/bin/eclipse"并保存

The underlying issue is that .bashrc is not loaded in a non-interactive shell. When you start Eclipse normally clicking on its symbol, .bashrcquits early. This solution applies to all programs that are defined by a .desktopfile. In contrast, bash -iopens an interactive shell, -c ""runs a command in that shell.

根本问题是 .bashrc 未加载到非交互式 shell 中。当您启动 Eclipse 时,通常单击其符号,.bashrc提前退出。此解决方案适用于由.desktop文件定义的所有程序。相反,bash -i打开一个交互式外壳,-c ""在该外壳中运行命令。

回答by Martin Peter

Your tooling probably utilizes the embedded eclipse terminal. This terminal does not start providing your login/user shell. So you need to set the eclipse terminal in your Eclipse preferences to start as --loginshell:

您的工具可能使用嵌入式 eclipse 终端。此终端不会开始提供您的登录名/用户 shell。因此,您需要在 Eclipse 首选项中设置 eclipse 终端以作为--loginshell启动:

Go to:

去:

Preferences -> Terminal -> Local Terminal

and set

并设置

"Arguments" to "--login"

restart Eclipse and your users $PATH should be used from now on.

重新启动 Eclipse,从现在开始应该使用您的用户 $PATH。

回答by Dawid Drozd

  1. Create simple script
  1. 创建简单脚本
#!/bin/bash
source /home/user/.environment_variables
/home/user/eclipse_cpp/eclipse -Duser.name="My Name"
#!/bin/bash
source /home/user/.environment_variables
/home/user/eclipse_cpp/eclipse -Duser.name="My Name"

2. Next put your all system variables in file /home/user/.environment_variables (any file you want)

2.接下来将所有系统变量放在文件/home/user/.environment_variables(您想要的任何文件)中

My looks like:

我的样子:

export COCOS_ROOT=/home/user/Projects/edukoala
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64/

3. Now you can delete your variables in .bashrc and put line

3. 现在您可以删除 .bashrc 中的变量并放置行

source /home/user/.environment_variables

Everything works fine :)

一切正常:)

回答by Sumod

Well, this is already answered and the answer has been accepted. But this will also work for running your code using Eclipse. You can edit the Run Configurations and set the environment variable there. Then, Eclipse will pick up the variable from this setting while building.

嗯,这已经回答了,答案已被接受。但这也适用于使用 Eclipse 运行您的代码。您可以编辑运行配置并在那里设置环境变量。然后,Eclipse 将在构建时从此设置中选取变量。