I am trying to write a script to go into a folder, find all the pom files in there located in different directories and change their version. I think the issue is with my sed command cos currently I am not getting any errors but the version doesn't change. Could I get some assistance on what I am doing wrong please. Thanks.
#!/bin/bash
mainPath=/Users/name/bin/proj/simulators
oldPOMVersion=$1
newPomVersion=$2
find $mainPath -name "pom.xml" | while read filePath; do
if grep -aq "<version>$1</version>" $filePath
then
echo "=================================================="
echo "Switching version for $filePath ..."
sed -i "" 's/$1/$2/g' $filePath
fi
done
Calling the script as follows which outputs no errors but doesn't change the POM file versions as expected. Note that there will be no conflicts with other dependencies in that file due to the 'guardian' text in the version below which is unique. The filePath is correct (grep works) for each file based on the echo in the script.
bash updt.sh 5.7-guardian-SNAPSHOT 5.8-guardian-SNAPSHOT