如何使用新的环境变量打开gnome-terminal?

时间:2021-08-19 20:20:39

I have a file that sets enviroment variables(JAVA_HOME, ANT_HOME...) I use for doing java programming related tasks. WHen I want to setup the new environment I type "source devenv" (devenv being the file that contains the new environment setup). I'm trying to create a shortcut that opens the gnome-terminal and automatically sets those variables, but I'm unsure how. I tried : "gnome-terminal --command="source devenv" with no success.

我有一个文件设置环境变量(JAVA_HOME,ANT_HOME ...)我用来做java编程相关的任务。当我想设置新环境时,我输入“source devenv”(devenv是包含新环境设置的文件)。我正在尝试创建一个打开gnome-terminal的快捷方式并自动设置这些变量,但我不确定如何。我试过:“gnome-terminal --command =”source devenv“没有成功。

My devenv file :

我的devenv档案:

#!/bin/bash
JAVA_HOME=./jdk1.6.0_21
export PATH=$JAVA_HOME/bin:$PATH
export ANT_HOME=./apache-ant-1.8.1
PS1="[jdkenvironment] \w @ "
/bin/bash

When I type echo $JAVA_HOME the following is printed :

当我键入echo $ JAVA_HOME时,将打印以下内容:

thiago@thiago-laptop:~/jdk$ echo $JAVA_HOME

thiago@thiago-laptop:~/jdk$

1 个解决方案

#1


0  

If you're ok with adding a call to /bin/bash or whatever shell at the end of devenv, this should work:

如果您可以在devenv末尾添加对/ bin / bash或任何shell的调用,那么这应该可行:

gnome-terminal --command="bash devenv"

If you use devenv to set a variable foo, it will need to look like this:

如果使用devenv设置变量foo,则需要如下所示:

#!/bin/bash
set foo=2
export foo
/bin/bash

#1


0  

If you're ok with adding a call to /bin/bash or whatever shell at the end of devenv, this should work:

如果您可以在devenv末尾添加对/ bin / bash或任何shell的调用,那么这应该可行:

gnome-terminal --command="bash devenv"

If you use devenv to set a variable foo, it will need to look like this:

如果使用devenv设置变量foo,则需要如下所示:

#!/bin/bash
set foo=2
export foo
/bin/bash