我在这里运行RHEL 7和bash。命令替换似乎不适用于umount命令。但是,对于其他命令,它可以像往常一样工作。例如:
[root@localhost ~]# msg=$(umount /u01)
umount: /u01: target is busy.
(In some cases useful info about processes that use
the device is found by lsof(8) or fuser(1))
[root@localhost ~]# echo "$msg"
- nothing here -
[root@localhost ~]# msg=$(mountpoint /u01)
[root@localhost ~]# echo "$msg"
/u01 is a mountpoint我可能要做的就是先使用mountpoint,然后再umount,如果这个mountpoint存在的话。然后检查umount状态-如果有错误,我猜设备一定是忙。
发布于 2019-05-10 14:24:18
可能是umount将这些错误写入标准错误输出流。使用命令替换$(..),您只能捕获标准输出流。正确的修复方法应该是
msg="$(umount /u01 2>&1)"但是,您可以依赖这些命令的退出代码,而不是依赖于冗长的信息,即first check
if mountpoint /u01 2>&1 > /dev/null; then
if ! umount /u01 2>&1 > /dev/null; then
printf '%s\n' "/u01 device must be busy"
else
printf '%s\n' "/u01 device is mounted"
fi
fi上面的版本安全地使这两个命令生成的输出字符串无效,并且只打印设备的挂载状态。part 2>&1 >/dev/null简称为part,将所有标准错误重定向到标准输出,并将它们组合放入空设备,以便它们在终端窗口上可见。
https://stackoverflow.com/questions/56071768
复制相似问题