【发布时间】:2011-09-25 12:21:06
【问题描述】:
如果输出为空,我想返回退出状态 0,否则返回 1:
find /this/is/a/path/ -name core.*
【问题讨论】:
如果输出为空,我想返回退出状态 0,否则返回 1:
find /this/is/a/path/ -name core.*
【问题讨论】:
当你说你希望它返回一个特定的数字时,你指的是退出状态吗?如果是这样:
[[ -z `find /this/is/a/path/ -name core.*` ]]
而且由于您只关心是/否响应,您可能希望将您的发现更改为:
[[ -z `find /this/is/a/path/ -name core.* -print -quit` ]]
在找到第一个核心文件后将停止。否则,如果根目录很大,查找可能需要一段时间。
【讨论】:
-z 是正确的
这是我的版本。 :)
[ -z "$(find /this/is/a/path/ -name 'core.*')" ] && true
为简洁而编辑:
[ -z "$(find /this/is/a/path/ -name 'core.*')" ]
【讨论】:
可能有很多变种,但这是一个:
test $(find /this/is/a/path/ -name core.* | wc -c) -eq 0
【讨论】:
也许是这样
find /this/is/a/path/ -name 'core.*' | read
【讨论】:
我正在使用这个:
if test $(find $path -name value | wc -c) -eq 0
then
echo "has no value"
exit
else
echo "perfect !!!"
fi
【讨论】: