Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Awk 如何在shell脚本中检查Find statment的返回值?_Awk_Shell - Fatal编程技术网

Awk 如何在shell脚本中检查Find statment的返回值?

Awk 如何在shell脚本中检查Find statment的返回值?,awk,shell,Awk,Shell,如何在shell脚本中检查“Find”语句的返回值 我在脚本中使用Find,如果Find语句找不到任何文件,则执行退出!! 我想检查“Find”的返回值,如果它找到或没有找到任何文件您可以使用wc-l命令计算Find找到的文件数: export result=`find . -name *.txt | wc -l` 您现在可以检查result,查看找到的文件数量 if [ $result == "0" ]; then echo zero found; fi 您可以将find命令的输出重定

如何在shell脚本中检查“Find”语句的返回值 我在脚本中使用Find,如果Find语句找不到任何文件,则执行退出!!
我想检查“Find”的返回值,如果它找到或没有找到任何文件

您可以使用
wc-l
命令计算
Find
找到的文件数:

 export result=`find . -name *.txt | wc -l`
您现在可以检查
result
,查看找到的文件数量

 if [ $result == "0" ]; then echo zero found; fi

您可以将
find
命令的输出重定向到一个名为say
output.txt的文件,然后使用
-s
选项检查该文件的大小是否为0

if [[ -s "output.txt" ]]
then
echo "File is not empty!"
else
echo "File is empty!"
fi