微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

linux – 退出重定向命令的代码

所以我想验证特定命令的退出代码

runuser -s /bin/bash @user_name -c $command > /dev/null 2>&1 &

如何查找命令runuser -s / bin / bash @user_name -c $命令是否正确执行?
我试过用$?但它不起作用,因为它始终为0(重定向的结果为0)

如何找到该命令的退出代码

最佳答案
由于任务的背景(通过&)而不是重定向,退出代码不可用.

您应该使用wait获取后台任务的退出代码.

wait command stop script execution until all jobs running in
background have terminated,or until the job number or process id
specified as an option terminates. It returns the exit status of
waited-for command.

原文地址:https://www.jb51.cc/linux/440448.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐