Bash MAC OS Maven:无法识别导出的环境变量

Bash MAC OS Maven:无法识别导出的环境变量,bash,macos,shell,maven,environment-variables,Bash,Macos,Shell,Maven,Environment Variables,我想使用shell脚本构建一个maven项目。考虑方案 在我的项目中,我有一些测试,例如 public class MyTest{ @Before public void setUp() { String libPath = System.getenv("LIBRARY_PATH"); if (libPath == null || libPath.isEmpty()) { logger.error( "LIBRARY_PATH not fo

我想使用shell脚本构建一个maven项目。考虑方案

在我的项目中,我有一些测试,例如

public class MyTest{

  @Before
  public void setUp() {
   String libPath = System.getenv("LIBRARY_PATH");
    if (libPath == null || libPath.isEmpty()) {
      logger.error(
          "LIBRARY_PATH not found. Please set this env variable to denote the location of the binaries that need to be loaded");
      throw new IllegalArgumentException(
          "LIBRARY_PATH not found. Please set this env variable to denote the location of the binaries that need to be loaded");
    }
    logger.info("LIBRARY_PATH found. All the binaries will be loaded from here {}", libPath);
}
/*Some tests that depend on LIBRARY_PATH being set*/
} 
现在,我有一个shell脚本
build\u project
,它执行以下操作

#!/bin/bash -e

if [ -z $1 ] ; then
    echo "Must provide LIBRARY_PATH"
    exit 1
fi

source setup_work.sh $1

mvn clean install
下面是
setup\u work.sh
脚本

#!/bin/bash -e

export LIBRARY_PATH=$PWD/$1
echo "LIBRARY_PATH is ${LIBRARY_PATH}"
# some other setup tasks specific to my project
最后,我所做的就是跑步

build\u project.sh/some/path/

它在linux/ubuntu上运行得非常好

但是,它在MAC OS上不起作用。我明白了

LIBRARY_PATH is workingDir/some/path/
/*
lots of maven messages
.
.
.
*/
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running my.project.package.MyTest
[ERROR] LIBRARY_PATH not found. Please set this env variable to denote the location of the binaries that need to be loaded
IllegalArgumentException
问题出在maven还是MAC OS上?为什么我不能从shell脚本导出env变量

最后,请注意,如果我在我的
bash\u配置文件中添加以下内容

export LIBRARY\u PATH=some/PATH/i/need

然后它在MAC OS上工作。这让我相信问题在于MAC OS


我做错了什么?

如果在
源代码之后但在
mvn
之前运行,您的路径是否会出现在
env
的输出中?是的,这是奇怪的部分。在调用maven之前,我有一个echo语句,我可以在控制台上清楚地看到env变量设置为
echo
只输出shell变量的值,不管它是否实际导出。在
source
返回后运行
env
将有助于验证变量是否真正导出,在这种情况下,
mvn
存在问题。哦,好的,让我试试,我可以确认env变量已设置。我添加了
env | grep LIBRARY_PATH
,并在控制台上看到了该值