我使用以下命令执行bash脚本:
./testscript &
它包括:
#!/bin/bash
export testvar=OK
...
如何从其他bash脚本访问testvar?
答案 0 :(得分:2)
您需要使用以下内容将testscript
中的内容输入到另一个脚本中:
source ./testscript
或者其他:
. ./testscript
这样就可以避免在执行./testscript
时创建子shell,因此创建的变量仍然在范围内。