我如何检查shell脚本中" Find“语句的返回值,如果find语句没有找到任何文件,则执行退出!!我想检查"Find“的返回值是否找到任何文件
发布于 2011-01-04 23:25:08
您可以将find命令的输出重定向到一个名为output.txt的文件,然后可以使用-s选项检查该文件的大小是否为0;
if [[ -s "output.txt" ]]
then
echo "File is not empty!"
else
echo "File is empty!"
fi发布于 2011-01-04 23:21:14
您可以使用wc -l命令统计find找到的文件数量:
export result=`find . -name *.txt | wc -l`您现在可以检查result以查看找到了多少个文件
if [ $result == "0" ]; then echo zero found; fihttps://stackoverflow.com/questions/4595078
复制相似问题