使用shell脚本在当前目录中查找pom.xml

问题描述 投票:0回答:1

我正在尝试在当前目录的子目录中构建所有maven项目。我的shell脚本说无论文件是否存在,都会找到pom文件。我不确定我做错了什么。请有人帮忙。

我的shell脚本是

#!/bin/bash
#############################################################
#Simple script to build all project in the current directory
#############################################################

dirlist=$(find $1 -mindepth 1 -maxdepth 1 -type d)

for dir in $dirlist
 do 
   (
   cd $dir
   echo "############################################################################"
   echo "inside directory: " $dir
   echo "############################################################################"
   git checkout development
   git pull
   if find . -maxdepth 1 -type f -name "pom.xml" # <- this is always true#
    then
     echo "========== Pom file exists to going for building ========= "
     mvn clean install -DskipTests=true
    fi
   )
 done
shell unix
1个回答
1
投票

find的退出状态为0,即使它没有找到任何内容。例如,对于像非空目录的-delete这样的情况,它不是零,但不是因为没有找到任何东西。

$ ls
file1.txt
$ find -name 'file2.txt'
$ echo $?
0

您可以在您的情况下检查是否存在:

if [[ -e 'pom.xml' ]]; then
© www.soinside.com 2019 - 2024. All rights reserved.