I am trying build all maven projects in a sub directory of the current directory. My shell script is saying that pom file is found irrespective whether file is exists or not. I am not sure if I am doing anything wrong. Could someone please help.
My shell script is
#!/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. It's non-zero for cases like a -delete
of a non-empty directory, for example, but not for not finding anything.
$ ls
file1.txt
$ find -name 'file2.txt'
$ echo $?
0
You could just check for existence in your condition instead:
if [[ -e 'pom.xml' ]]; then
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.