Re: How to read out plist information and compare version number?
Re: How to read out plist information and compare version number?
- Subject: Re: How to read out plist information and compare version number?
- From: Adam Peck <email@hidden>
- Date: Thu, 13 Nov 2008 10:05:22 -0700
- Thread-topic: How to read out plist information and compare version number?
Hi,
You cannot compare versions as strings because this will almost never work
as intended. You must split them into their parts and compare those. This
perl snippet should give you some idea on what should be done:
# Versions are compared fist on MajorVersion then Minor then Build and then
Patc
h number.
sub versionCmp
{
my @verA = split(/\./, $_[0]);
my @verB = split(/\./, $_[1]);
for my $i (0 .. scalar(@verA)-1)
{
return 1 if ($verA[$i] < $verB[$i]);
return -1 if ($verB[$i] < $verA[$i]);
}
return 0;
}
On 13/11/08 9:59 AM, "David Schara" <email@hidden>
wrote:
> Hi,
>
> I tried to create a bash file that should be able to read out an
> application version number which is located in a plist and compare it to
> a different version number. Both version numbers have the same
> appearance: x.y.zzz
>
> This is my code:
> ______
> #!/bin/sh
> # postflight
>
> VERSION_NEW="0.5.002"
>
> VERSION=defaults read "/Applications/My.app/Contents/Info"
> "CFBundleShortVersionString"
>
> echo $VERSION
>
> if[$VERSION_NEW -lt $VERSION]; then
> echo "Version is bigger"
> else
> echo "Version is smaler"
> fi
> ______
> I know there must be something wrong with the if-clause because I try to
> compare two Strings , but I have no clue how to treat a version number
> correctly. Also I get a strange error message (read:
> `/Applications/Maschine.app/Contents/Info': not a valid identifier).
> What is wrong there?
>
> THX
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Installer-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Installer-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden