shell脚本之间导出变量 [英] Exporting variables between shell script

查看:161
本文介绍了shell脚本之间导出变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个独立运行的脚本。
第一个可以说一个脚本计算一些值。我想呼应从名为B.这些脚本不会相互调用其他脚本这些值。我已经使用出口关键字,但没有奏效。我怎样才能做到这一点?

I have two independently running scripts. first one lets say script A calculates some values. And i want to echo these values from other script called B. These scripts will not call each other. I have used export keyword but didn't work. How can i do this?

推荐答案

如果我理解的要求则不能同时脚本简单地在同一子shell中执行,但独立的没有互相调用或而不需要任何外部文件或管这样的:

If I understood the requirement then can't both scripts be simply executed in same sub shell, independently but without calling each other or without any need of an external file or pipe like this:

让我们说这是您的 script1.sh

#!/bin/bash
# script1.sh: do something and finally
export x=19

在这里我们您的 script2.sh

#!/bin/bash
# script2.sh: read value of $x here
echo "x="${x}

刚刚打电话给他们在这样的同一子壳

Just call them in same sub-shell like this

(. ./script1.sh && ./script2.sh)

OUTPUT:

x=19

这篇关于shell脚本之间导出变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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