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.

相关文章

Linux中的ARP防火墙主要用于防御ARP欺骗攻击,其效果取决于多...
insmod和modprobe加-f参数导致Invalid module format错误 这...
将ArchLinux安装到U盘 几个月前入门Arch的时候上网搜了不少安...
1、安装Apache。 1)执行如下命令,安装Apache服务及其扩展包...
一、先说一下用ansible批量采集机器信息的实现办法: 1、先把...
安装配置 1. 安装vsftpd 检查是否安装了vsftpd # rpm -qa | ...