Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
管道.sh
export START=100 . ./other.sh & wait
其他.sh
sleep 5 export END=200
但我没有看到变量END在export -p. 如果我在前台获取 other.sh它虽然有效。
export -p
export START=100 . ./other.sh
如何从后台进程中导出变量?有什么解决办法吗?
子进程无法更改父环境,您需要以某种方式从父进程声明变量。例如使用文件:
管道.sh:
export START=100 . ./other.sh > tmp & wait source tmp rm tmp echo $END
其他.sh:
sleep 5 echo "export END=200"
另请参阅此答案。