Reputation: 23
I'm trying to make a script to get the latest version of a GitHub project and check if it has been updated. The script is:
#!/bin/bash
getVersion(){
curl --silent "https://api.github.com/repos/pwn20wndstuff/Undecimus/releases/latest" |
grep '"tag_name":' |
sed -E 's/.*"([^"]+)".*/\1/'
}
writeVersion(){
func_result="$(getVersion)"
echo $func_result > version.txt
}
checkForUpdate(){
currentVersion=$(cat version.txt)
latestVersion="$(getVersion)"
if [ "$currentVersion" == "$version" ]; then
echo "Strings are equal"
else
echo "Strings are not equal"
echo "current version is: $currentVersion"
echo "latest version is: $latestVersion"
fi
}
output of ./get_latest_release.sh checkForUpdate
:
Strings are not equal
current version is: v4.2.1
latest version is: v4.2.1
As you can see, the versions are the same yet the if then
check is returning that they are different rather than Strings are equal
Any help is appreciated.
Upvotes: 0
Views: 152
Reputation: 20012
Your check
if [ "$currentVersion" == "$version" ]; then
should be
if [ "$currentVersion" == "$latestVersion" ]; then
Upvotes: 2