加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

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

发布时间:2020-12-14 02:11:05 所属栏目:Linux 来源:网络整理
导读:所以我想验证特定命令的退出代码 runuser -s /bin/bash @user_name -c $command /dev/null 21 如何查找命令runuser -s / bin / bash @user_name -c $命令是否正确执行? 我试过用$?但它不起作用,因为它始终为0(重定向的结果为0) 如何找到该命令的退出代码?
所以我想验证特定命令的退出代码

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读