Sponsored Content
Full Discussion: compare versions.
Top Forums Shell Programming and Scripting compare versions. Post 302537978 by aigles on Monday 11th of July 2011 10:10:51 AM
Old 07-11-2011
A ksh solution :
Code:
#!/usr/bin/ksh
# Usage: $0 version1 version2

set -o nounset

oIFS="$IFS" ;IFS='.'
set -A v1 $1
set -A v2 $2
IFS="${oIFS}"

cnt1=${#v1[*]}
cnt2=${#v2[*]}
(( cnt1 > cnt2 )) && cnt=$cnt1 || cnt=$cnt2;

i=0
result="EQUAL"
while (( i <= cnt ))
do
    (( n1 = ${v1[$i]-} + 0 ))
    (( n2 = ${v2[$i]-} + 0 ))
    if (( n1 > n2 ))
    then
        result="GREATER"
        break
    elif (( n1 < n2 ))
    then
        result="LOWER"
        break
    fi
    (( i += 1 ))
done

print ${result} $1 $2

Examples:
Code:
$ ./cmpv.ksh 1.2.3 1.2.3
EQUAL 1.2.3 1.2.3
$ ./cmpv.ksh 1.2.4 1.2.3
GREATER 1.2.4 1.2.3
$ ./cmpv.ksh 1.2.4 1.2.4.1
LOWER 1.2.4 1.2.4.1

Jean-Pierre.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

different versions?

can someone tell me a shell-script to convert an older version of a file with the current one? (1 Reply)
Discussion started by: deeptia
1 Replies

2. UNIX Desktop Questions & Answers

Need to know all versions of Unix

:confused: What are some of the most popular versions of Unix and why? (2 Replies)
Discussion started by: jpawlicki2
2 Replies

3. UNIX for Dummies Questions & Answers

Versions of UNIX

Hi all: I was just wondering if someone could tell me what versions of UNIX are available to public? I'm aware of all the available distro's for Linux e.g. Debain, SuSe, RedHat, etc ... However you never really here much about UNIX distro's! Is UNIX BDS a common one in use? Thanks Oliver (4 Replies)
Discussion started by: oliver79
4 Replies

4. HP-UX

Is there any way to get old HP-UX versions?

I got my hands on a HP9000/380 and need a (really) old version of HP-UX, like 7 or 8. Is there any vendor who sells older versions? I did a quick search here and checked the FAQ and HPs HP-UX site but couldn't find anything. :confused: Any help is appreciated! (4 Replies)
Discussion started by: dlundh
4 Replies

5. UNIX for Dummies Questions & Answers

Versions of HP-UX or AIX

Can I install a HP-UX or IBM AIX in my home pc?. It is a Intel Pentium 4 of 64 bits. Is there any version for me?. (5 Replies)
Discussion started by: kurt1978
5 Replies

6. Solaris

Solaris versions

Hi, Does anyone know if the various releases of Solaris are archived anywhere? I work for a DR company and it would be useful to have different releases of a Solaris version number i.e. Solaris 10 6/06 (3 Replies)
Discussion started by: callmebob
3 Replies

7. UNIX for Advanced & Expert Users

What are these kernel versions?

2.6.32-028stab094.3 x86_64 vs 2.6.32-5-amd64 x86_64 and where can i download the first one? thx (1 Reply)
Discussion started by: suffeks
1 Replies

8. HP-UX

Versions of HP-UX

Lo guys, I've just started a new department in work and I'm going to be using HP-UX with Vi. The problem is I'm completely new to UNIX, I'm currently learning at work but I only have limited amounts of time on our dev systems. Is it possible to get a free/educational version any where? I don't... (4 Replies)
Discussion started by: john2012
4 Replies

9. Linux

Different versions of Linux

Hello Friends, Please anyone share with me, the name of different versions of Linux? Which are the latest versions of Linux ?? (2 Replies)
Discussion started by: ggiwebsinfo
2 Replies

10. Fedora

All different versions of UNIX

Hello, I am very new at this and would like to know how many versions of Unix there are and all of the different versions of unix. (3 Replies)
Discussion started by: rosanna azani
3 Replies
CHDIST(1)																 CHDIST(1)

NAME
chdist - script to easily play with several distributions SYNOPSIS
chdist [options] [command] [command parameters] DESCRIPTION
chdist is a rewrite of what used to be known as 'MultiDistroTools' (or mdt). Its use is to create 'APT trees' for several distributions, making it easy to query the status of packages in other distribution without using chroots, for instance. OPTIONS
-h, --help Provide a usage message. -d, --data-dir DIR Choose data directory (default: $HOME/.chdist/). -a, --arch ARCH Choose architecture (default: `dpkg --print-architecture`). --version Display version information. COMMANDS
create DIST [URL RELEASE SECTIONS] Prepare a new tree named DIST apt-get DIST <update|source|...> Run apt-get inside DIST apt-cache DIST <show|showsrc|...> Run apt-cache inside DIST apt-rdepends DIST [...] Run apt-rdepends inside DIST src2bin DIST SRCPKG List binary packages for SRCPKG in DIST bin2src DIST BINPKG List source package for BINPKG in DIST compare-packages DIST1 DIST2 [DIST3, ...] compare-bin-packages DIST1 DIST2 [DIST3, ...] List versions of packages in several DISTributions compare-versions DIST1 DIST2 compare-bin-versions DIST1 DIST2 Same as compare-packages/compare-bin-packages, but also runs dpkg --compare-versions and display where the package is newer. compare-src-bin-packages DIST Compare sources and binaries for DIST compare-src-bin-versions DIST Same as compare-src-bin-packages, but also run dpkg --compare-versions and display where the package is newer grep-dctrl-packages DIST [...] Run grep-dctrl on *_Packages inside DIST grep-dctrl-sources DIST [...] Run grep-dctrl on *_Sources inside DIST list List available DISTs COPYRIGHT
This program is copyright 2007 by Lucas Nussbaum and Luk Claes. This program comes with ABSOLUTELY NO WARRANTY. It is licensed under the terms of the GPL, either version 2 of the License, or (at your option) any later version. Debian Utilities 2013-12-23 CHDIST(1)
All times are GMT -4. The time now is 05:40 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy