linux - Bash 获取等待进程的退出代码

标签 linux bash shell

我想获取我正在等待的进程的退出代码并返回它。 我有一个名为 script.sh 的脚本,看起来像这样:

#!/bin/bash

path="/PATH/TO/SCRIPT/another_script.sh"
$path
wait
cleanUpFunction

如何从 script.sh 返回 another_script.sh 的退出代码?

最佳答案

你没有在后台运行 another_script.sh,所以你根本不需要wait

another_script.sh
exit_code=$?

不过,如果您wait 的退出状态就是后台进程的退出状态。

another_script.sh &
# Do some other stuff
wait
exit_code=$?

关于linux - Bash 获取等待进程的退出代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44616562/

相关文章:

php - 如何在 ubuntu 14.04 上安装 php 5.3.10

linux - 在字符 bash 第二次出现后替换子字符串

linux - 关于使用 Ada 的包体要求的令人费解的 "info"消息?

bash - 是否可以在 Makefile 中设置环境变量 - 之后使用

bash - 对某些目录 makefile 中的文件进行简单循环

bash - ulimit 硬(-H)和软(-S)的含义

linux - 如何在参数中插入单独的行(元素)

c - Debian 中 login_cap.h 的 rlim_t 错误

linux - bash 脚本 - 我想检查 XLS 是否为空。如果是,我什么都不想做。如果不是,我想做点什么

php - 用于运行 php 脚本的 Bash 脚本