使用 bash 脚本提取 ldd --version

Extracting ldd --version with bash script

我正在尝试通过提取 ldd --version 输出来验证 glibc 版本。这是来自 Ubuntu 机器的示例:

ldd (Ubuntu GLIBC 2.21-0ubuntu4) 2.21

这是 CentOS 6.5 机器上的另一个:

ldd (GNU libc) 2.17

谢谢,

克里斯

使用 awk:

$ ldd --version | awk '/ldd/{print $NF}'
2.19

基本上,如果该行包含字符串 ldd,则打印最后一个字段。

发现您正在使用的 libc 版本的正确方法是执行 libc.so 文件。是的,这很奇怪,但这是你应该做的,ld --version 因为 ldconfig --version 不是正确的方法。

$ /lib/powerpc64le-linux-gnu/libc.so.6
GNU C Library (Ubuntu GLIBC 2.21-0ubuntu4) stable release version 2.21, by Roland McGrath et al.
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.9.2.
Available extensions:
    crypt add-on version 2.1 by Michael Glad and others
    GNU Libidn by Simon Josefsson
    Native POSIX Threads Library by Ulrich Drepper et al
    BIND-8.2.3-T5B
libc ABIs: UNIQUE IFUNC
For bug reporting instructions, please see:
<https://bugs.launchpad.net/ubuntu/+source/glibc/+bugs>.