tar version comparison

Darren Weber dweber at macports.org
Wed Jul 1 14:16:38 PDT 2009


I need to test if the system has a tar version between 1.14 and 1.14.90,
what is the best way to do this in tcl?

I have the following tcl script snippet, but there may be an easier way.

# tar-1.14 uses --strip-path, tar-1.14.90+ uses --strip-components
set tarArg "--strip-components"
set tarVersion [lrange [split [exec tar --version]] 3 3]
set tarMaj [lrange [split $tarVersion .] 0 0]
set tarMin [lrange [split $tarVersion .] 1 1]
set tarRev [lrange [split $tarVersion .] 2 2]
if ([expr $tarMaj == 1 && $tarMin == 14 && $tarRev < 90]) {
      set tarArg "--strip-path"
}

For example, on OSX 10.5.x we get these results from /usr/bin/tar:

% set tarVer [lrange [split [exec tar --version]] 3 3]
1.15.1
% set tarMaj [lrange [split $tarVer .] 0 0]
1
% set tarMin [lrange [split $tarVer .] 1 1]
15
% set tarRev [lrange [split $tarVer .] 2 2]
1
% set tarArg "--strip-components"
--strip-components
% if ([expr $tarMaj == 1 && $tarMin == 14 && $tarRev < 90]) {
set tarArg "--strip-path"
}
% puts $tarArg
--strip-components
0
%

TIA,
Darren
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-dev/attachments/20090701/cec3ceeb/attachment-0001.html>


More information about the macports-dev mailing list