簡體   English   中英

使用Shell腳本在當前目錄中查找pom.xml

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

我正在嘗試在當前目錄的子目錄中構建所有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

即使未找到任何內容, find的退出狀態也為0。 例如,對於非空目錄的-delete之類的情況,它為非零,但不是找不到任何東西。

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

您可以只檢查條件是否存在:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM