Bash:计算在文件夹中查找结果

BoD*_*003 1 bash if-statement find

我试图计算有多少文件可以"找到"脚本,如果它不止一个,给出一种错误信息,如果它的零给出另一个错误信息.

如果我跑

find procesoSitemap-*.jar -exec printf '.' \;| wc -c
Run Code Online (Sandbox Code Playgroud)

它工作,我可以看到搜索结果的数量,但我怎么能在脚本中实现它?

##!/bin/bash
FINDPS="find procesoSitemap-*.jar -exec printf '.' \;| wc -c"

    if $FINDPS = 1
    then
            echo "There is ONE procesoSitemap jar file"
    else
            echo "There should be only ONE procesoSitemap jar file"
    fi
Run Code Online (Sandbox Code Playgroud)

谢谢!

ism*_*ail 6

使用反引号;

FINDPS=`find procesoSitemap-*.jar -exec printf '.' \;| wc -c`
Run Code Online (Sandbox Code Playgroud)

也修好你的if路线;

if [ $FINDPS -eq 1 ]
then
        echo "There is ONE procesoSitemap jar file"
else
        echo "There should be only ONE procesoSitemap jar file"
fi
Run Code Online (Sandbox Code Playgroud)