一回地面出口过程中不工作 [英] Export doesnt work for a back ground process

查看:126
本文介绍了一回地面出口过程中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pipe.sh

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

other.sh

other.sh

sleep 5
export END=200

但我没有看到在出口-p变量结束。但我看到它,如果pipe.sh改为

but I dont see the variable END in "export -p". But I do see it if change the pipe.sh to

 export START=100
 . ./other.sh 

如何导出从后台进程的变量?任何变通?

how do I export variables from background process? Any work arounds?

推荐答案

一个子进程不能改变父母的环境中,你需要以某种方式宣布从父变量。例如使用一个文件:

A child process cannot change parents environment, you need to declare the variable from the parent somehow. For example using a file:

pipe.sh:

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

other.sh:

other.sh:

sleep 5
echo "export END=200"

也看到这个答案

这篇关于一回地面出口过程中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆