导出在后台进程中不起作用 [英] export doesn't work in a background process

查看:58
本文介绍了导出在后台进程中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

pipe.sh

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

other.sh

sleep 5
export END=200

但是在export -p中看不到变量 END .如果我在前景中提供 other.sh ,它仍然可以工作.

But I don't see the variable END in export -p. If I source other.sh in the foreground it works though.

 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:

sleep 5
echo "export END=200"

也请参见此答案.

这篇关于导出在后台进程中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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