【问题标题】:Calling and returning a value from shell script using nohup使用 nohup 从 shell 脚本调用和返回值
【发布时间】:2016-08-08 10:28:32
【问题描述】:

我有两个 shell 脚本文件。一个是在系统上安装某些东西的通用文件,另一个是处理某些安装步骤的文件。

file1:主安装文件 file2:安装辅助文件

我从 file1 调用 file2 使用

 nohup ./file2.sh $1 </dev/null >../logs/schema.log 2>&1 &
 schema_status=$?
 echo $schema_status

现在因为 nohup schema_status 值总是为 0。

如何将相关值从 file2 返回到 file1。

在file2中,我添加了return语句:

if (condition)
then
   exit 101
else
   exit 102
fi

【问题讨论】:

    标签: shell ksh


    【解决方案1】:

    请浏览讨论与您类似的问题的链接。它建议您在file1.sh 中导出一个环境变量,然后在file2.sh 中设置此环境变量。这样,您将能够(间接)从 file2.sh 返回到 file1.sh

    Pass all variables from one shellscript to another?

    【讨论】:

      【解决方案2】:

      当 file1 正在调用 file2 并等待结果时,不要使用 nohup 启动 file2。当file2耗时较长时,可以用nohup启动file1。

      【讨论】:

        猜你喜欢
        • 2011-08-29
        • 2022-10-20
        • 1970-01-01
        • 2013-07-16
        • 2016-03-14
        • 1970-01-01
        • 2014-05-25
        • 2013-08-10
        • 1970-01-01
        相关资源
        最近更新 更多