简体   繁体   English

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

[英]Finding pom.xml in current directory using shell script

I am trying build all maven projects in a sub directory of the current directory. 我正在尝试在当前目录的子目录中构建所有Maven项目。 My shell script is saying that pom file is found irrespective whether file is exists or not. 我的Shell脚本说找到pom文件,而不管文件是否存在。 I am not sure if I am doing anything wrong. 我不确定自己做错了什么。 Could someone please help. 有人可以帮忙。

My shell script is 我的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

The exit status of find is 0, even if it doesn't find anything. 即使未找到任何内容, find的退出状态也为0。 It's non-zero for cases like a -delete of a non-empty directory, for example, but not for not finding anything. 例如,对于非空目录的-delete之类的情况,它为非零,但不是找不到任何东西。

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

You could just check for existence in your condition instead: 您可以只检查条件是否存在:

if [[ -e 'pom.xml' ]]; then

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM