#!/bin/bash
fuser /mount/foo
echo $?
if [ $? = 0 ]; then
echo "There are no processes accessing foo."
else
echo "foo is in use."
回声$?返回'1‘,因为fuser进程正在访问挂载-而不是回显“挂载正在使用”,“它回显”没有进程访问挂载。除了语法之外,我不确定是什么导致了这种相反的行为,但也许我完全不正确地构建它。
发布于 2014-07-31 14:21:40
第二个$?
计算echo
的结果,它应该是0。移除echo
或使用变量:
#!/bin/bash
fuser /mount/foo
result=$?
echo $result
if [ $result = 0 ]; then
echo "There are no processes accessing foo."
else
echo "foo is in use."
https://stackoverflow.com/questions/25061039
复制相似问题