1

管道.sh

 export START=100
 . ./other.sh &
 wait

其他.sh

sleep 5
export END=200

但我没有看到变量ENDexport -p. 如果我在前台获取 other.sh它虽然有效。

 export START=100
 . ./other.sh 

如何从后台进程中导出变量?有什么解决办法吗?

4

1 回答 1

2

子进程无法更改父环境,您需要以某种方式从父进程声明变量。例如使用文件:

管道.sh:

export START=100
. ./other.sh > tmp &
wait
source tmp
rm tmp 
echo $END

其他.sh:

sleep 5
echo "export END=200"

另请参阅此答案

于 2012-09-07T19:20:44.803 回答