Search code examples
linuxbashglibcldd

Extracting ldd --version with bash script


I am trying to verify the glibc version by extracting the ldd --version output. Here is an example from a Ubuntu machine:

ldd (Ubuntu GLIBC 2.21-0ubuntu4) 2.21

And here is another from a CentOS 6.5 machine:

ldd (GNU libc) 2.17

Thank you,

Chris


Solution

  • Using awk:

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

    Basically, if the line contains the string ldd, print the last field.