When I used perl -0777nE'%h;$h{$1}.="n".$2while/(GLIBCX*|CX*ABI)_([0-9.]+)/g;say$ARGV;print"t$_t".qx{echo "$h{$_}"|sort -V|tail -1}for(keys%h)' /usr/lib64/lib{stdc++,c}.so*
to get max versions, it is OK.
/usr/lib64/libstdc++.so.6
GLIBC 2.14
GLIBCXX 3.4.19
CXXABI 1.3.7
/usr/lib64/libstdc++.so.6.0.19
GLIBC 2.14
GLIBCXX 3.4.19
CXXABI 1.3.7
/usr/lib64/libc.so.6
GLIBC 2.17
GLIBCXX 3.4.19
CXXABI 1.3.7
But when using perl -0777nE'%h;$h{$1}.="n".$2while/(GLIBCX*|CX*ABI)_([0-9.]+)/g;say$ARGV;print"t$_t".qx{echo "$h{$_}"|sort -V|head -1}for(keys%h)' /usr/lib64/lib{stdc++,c}.so*
(change tail -1
to head -1
) to get min versions, it failed.
/usr/lib64/libstdc++.so.6
GLIBC
GLIBCXX
CXXABI
/usr/lib64/libstdc++.so.6.0.19
GLIBC
GLIBCXX
CXXABI
/usr/lib64/libc.so.6
GLIBC
GLIBCXX
CXXABI
I tried to use cat
to find the content of the $h{$_}"
variable, I found
[root@rh71 ~]# perl -0777nE'%h;$h{$1}.=$2."n"while/(GLIBCX*|CX*ABI)_([0-9.]+)/g;say$ARGV;print"t$_t".qx{cat<<<"$h{$_}"}for(keys%h)' /usr/lib64/lib{stdc++,c}.so*
... (many lines omitted)
3.4.19
CXXABI 1.3 <--- here, no new line
1.3.1
1.3.2
1.3.3
1.3.4
1.3.5
1.3.6
1.3.7
1.3
1.3.1
1.3.2
1.3.3
1.3.4
1.3.5
1.3.6
1.3.7
Change qx{cat<<<"$h{$_}"}
to qx{sort -uV<<<"$h{$_}"}
[root@rh71 ~]# perl -0777nE'%h;$h{$1}.=$2."n"while/(GLIBCX*|CX*ABI)_([0-9.]+)/g;say$ARGV;print"t$_t".qx{sort -uV<<<"$h{$_}"}for(keys%h)' /usr/lib64/lib{stdc++,c}.so*
... (many lines omitted)
3.4.19
CXXABI <--- here, a line end added
1.3
1.3.1
1.3.2
1.3.3
1.3.4
1.3.5
1.3.6
1.3.7
There was a new line after CXXABI
.
I wonder why…
Other or Background
- How to pipe the content of a variable as STDIN in a qx{} statement in Perl?
- Cannot compare two version string by calling perl oneliner from bash
- How can I print the names of the files being processed in a Perl one-liner?
[root@rh71 ~]# perl -Mversion -e 'exit !(version->parse("0.9.8.8")<version->parse("0.9.10.0"))'
Can't locate version.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .).
BEGIN failed--compilation aborted.
[root@rh71 ~]# perl -v
This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
(with 28 registered patches, see perl -V for more detail)
Copyright 1987-2012, Larry Wall
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
[root@rh71 ~]# grep -H . /etc/*release* # more /etc/*release*|cat
/etc/os-release:NAME="Red Hat Enterprise Linux Server"
/etc/os-release:VERSION="7.1 (Maipo)"
/etc/os-release:ID="rhel"
/etc/os-release:ID_LIKE="fedora"
/etc/os-release:VERSION_ID="7.1"
/etc/os-release:PRETTY_NAME=RHEL
/etc/os-release:ANSI_COLOR="0;31"
/etc/os-release:CPE_NAME="cpe:/o:redhat:enterprise_linux:7.1:GA:server"
/etc/os-release:HOME_URL="https://www.redhat.com/"
/etc/os-release:BUG_REPORT_URL="https://bugzilla.redhat.com/"
/etc/os-release:REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"
/etc/os-release:REDHAT_BUGZILLA_PRODUCT_VERSION=7.1
/etc/os-release:REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"
/etc/os-release:REDHAT_SUPPORT_PRODUCT_VERSION="7.1"
/etc/redhat-release:Red Hat Enterprise Linux Server release 7.1 (Maipo)
/etc/system-release:Red Hat Enterprise Linux Server release 7.1 (Maipo)
/etc/system-release-cpe:cpe:/o:redhat:enterprise_linux:7.1:ga:server
[root@rh71 ~]# gcc -v
bash: gcc: command not found...
[root@rh71 ~]# command -v gcc
[root@rh71 ~]# which gcc
/usr/bin/which: no gcc in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
[root@drh71 ~]# command -v strings
[root@rh71 ~]# ldd /usr/lib64/libstdc++.so.6 /usr/lib64/libc.so.6
/usr/lib64/libstdc++.so.6:
linux-vdso.so.1 => (0x00007fff4f1b1000)
libm.so.6 => /lib64/libm.so.6 (0x00007fe28c7c4000)
libc.so.6 => /lib64/libc.so.6 (0x00007fe28c403000)
/lib64/ld-linux-x86-64.so.2 (0x00007fe28cde0000)
libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007fe28c1ec000)
/usr/lib64/libc.so.6:
/lib64/ld-linux-x86-64.so.2 (0x00007f10a7bf0000)
linux-vdso.so.1 => (0x00007fff817fe000)
Explain why or better solution (a shorter command line and less dependence/module).