带全局变量的Bash脚本

时间:2014-10-16 11:06:45

标签: bash shell

我使用以下命令执行bash脚本:

./testscript &

它包括:

#!/bin/bash
export testvar=OK
...

如何从其他bash脚本访问testvar?

1 个答案:

答案 0 :(得分:2)

您需要使用以下内容将testscript中的内容输入到另一个脚本中:

source ./testscript

或者其他:

. ./testscript

这样就可以避免在执行./testscript时创建子shell,因此创建的变量仍然在范围内。