#!/bin/bash
fuser /mount/foo
echo $?
if [ $? = 0 ]; then
echo "There are no processes accessing foo."
else
echo "foo is in use."
Run Code Online (Sandbox Code Playgroud)
回声$?返回'1'是因为热熔器进程正在访问挂载 - 而不是回显"正在使用挂载",它回应"没有进程访问挂载".我不确定除语法之外可能导致这种相反的行为,但也许我正在完全错误地构建它.
你的第二个$?评估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."
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
801 次 |
| 最近记录: |