How do I determine what version of readline bash is using?

How do I determine what version of readline I am using in my bash session?

I am wondering specifically because I appear to have the readline library 6.3, but the set enable-bracketed-paste on in my .inputrc is working, even though that feature was only added in readline 7.0.

I am using bash 4.4.0 on macOS 10.11 (installed with Fink).


There is no generally reliable method of determining the version of a statically linked library. However, in this case, I believe you can use the value of the rl_readline_version global variable.

readline.h defines a C preprocessor variable that should be treated as an integer, RL_READLINE_VERSION, which may be used to conditionally compile application code depending on the installed Readline version. The value is a hexadecimal encoding of the major and minor version numbers of the library, of the form 0xMMmm. MM is the two-digit major version number; mm is the two-digit minor version number. For Readline 4.2, for example, the value of RL_READLINE_VERSION would be 0x0402.

https://tiswww.case.edu/php/chet/readline/readline.html#SEC25

As of bash-2.05a and later, this is exposed as rl_readline_version as you can see here:

int rl_readline_version = RL_READLINE_VERSION;

https://git.savannah.gnu.org/cgit/bash.git/tree/NEWS?id=d233b485e83c3a784b803fb894280773f16f2deb#n1542

The easiest way I know to check this is with a debugger like gdb. For example:

$ gdb bash
(gdb) print /x (int) rl_readline_version
$1 = 0x700

This means that my version of bash is running readline version 7.0.

In case you are curious, the readline maintainer has explained the reason for static linking on Mac OS X here:

  1. There is special handling to ensure the shell links against static versions of the included readline and history libraries on Mac OS X; Apple ships inadequate dynamic libreadline and libhistory "replacements" as standard libraries.

https://tiswww.case.edu/php/chet/bash/NOTES

Since readline is statically linked on Mac OS X, ldd and otool will not be helpful. However, for completeness, I will show you how it looks on Linux. Here is what mine looks like on Ubuntu 18.04:

$ ldd /bin/bash
    linux-vdso.so.1 (0x00007ffeb83c3000)
    libtinfo.so.5 => /lib/x86_64-linux-gnu/libtinfo.so.5 (0x00007fbcd7d57000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fbcd7b53000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fbcd7762000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fbcd829b000)

As you can see, the ldd output is also unhelpful in this case. So instead I used strace:

$ strace -o strace.log -f bash
# Have to do stuff with interactive mode; `bash -c exit` won't do it.
$ exit

I believe the corresponding dtrace command would be:

$ dtrace -o dtrace.log -f bash

but I haven't tried it, so I can't say for sure. At this point, I can just grep the logfile for readline:

$ grep readline strace.log
strace.log:30194 openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libreadline.so.7", O_RDONLY|O_CLOEXEC) = 3

So on Ubuntu 18.04 it is readline version 7, as expected.

$ dlocate -F '/lib/x86_64-linux-gnu/libreadline.so.7'
libreadline7:amd64: /lib/x86_64-linux-gnu/libreadline.so.7.0
libreadline7:amd64: /lib/x86_64-linux-gnu/libreadline.so.7
$ apt-cache policy libreadline7
libreadline7:
  Installed: 7.0-3
  Candidate: 7.0-3
  Version table:
 *** 7.0-3 500
        500 http://us.archive.ubuntu.com/ubuntu bionic/main amd64 Packages
        100 /var/lib/dpkg/status