我正在通过运行类似这样的 bash 脚本进行一些测试/home/travis/test_build.sh
。我有一个单独的脚本checkout.sh
来设置环境变量(我无法在 test_build.sh 之前调用它)。因此,/home/travis/test_build.sh
我在里面对其进行了源代码:. ./checkout.sh
。但是在使用 echo 执行之后,checkout.sh
我看到变量被设置回初始值(空)。有办法修复它吗?
简短示例 /home/travis/test_build.sh
#!/bin/bash
echo "what is 0: $0"
set -x
. ./checkout.sh
echo "COMP_ARCH=$COMP_ARCH"
echo "FRAME_BASE=$FRAME_BASE"
简短示例 checkout.sh
:
#!/bin/bash
echo "what is 0: $0"
set -e
export COMP_ARCH=slc6_amd64_gcc493
eval `scramv1 runtime -sh` # link scramv1 is set to some other script which is not mine, starts with `#!/bin/sh` and which is supposed to set some additional variables as FRAME_BASE
echo "COMP_ARCH=$COMP_ARCH"
echo "FRAME_BASE=$FRAME_BASE"
执行后的输出/home/travis/test_build.sh
将是:
what is 0: /home/travis/test_build.sh
what is 0: /home/travis/test_build.sh
COMP_ARCH=slc6_amd64_gcc493
FRAME_BASE=/home/1234/wer/base
COMP_ARCH=slc6_amd64_gcc493
FRAME_BASE=