# First try with no matching files
[ -n "$(find /tmp/file* -maxdepth 1 -type f -print -quit)" ] && echo yes || echo no # "no"
# Create some matching files and try the same command once more
touch /tmp/file.1 /tmp/file.43.434 /tmp/file-hegfegf
[ -n "$(find /tmp/file* -maxdepth 1 -type f -print -quit)" ] && echo yes || echo no # "yes"
Example #2 带for循环
found=
for file in /tmp/file*
do
[ -f "$file" ] && found=yes && break
done
[ yes = "$found" ] && echo yes || echo no # No files "no", otherwise "yes"
我会使用其中一个
find
或一个for
循环来识别这种情况。示例 #1
find
(使用 GNU 扩展来限制搜索空间):Example #2 带
for
循环