I am learning to write some scripts.
I try to convert a decimal number, the version of the os into an integer
So I use:
Code: Select all
/system package update get installed-version
Can I convert it into an integer to make some compares?
/system package update get installed-version
{
:local version [/system package update get installed-version]
:local numVersion
:for i from=0 to=([:len $version]-1) do={
:local tmp [:pick $version $i]
:if ($tmp !=".") do={
:set numVersion "$numVersion$tmp"
}
}
:set numVersion [:tonum $numVersion]
:put $numVersion
}
Works perfectly thanksThis loops trough the string and remove all the dots, then convert it to a number.
Try cut and past this to command line to see the result.Code: Select all{ :local version [/system package update get installed-version] :local numVersion :for i from=0 to=([:len $version]-1) do={ :local tmp [:pick $version $i] :if ($tmp !=".") do={ :set numVersion "$numVersion$tmp" } } :set numVersion [:tonum $numVersion] :put $numVersion }
Based on script found here:
viewtopic.php?t=32125