gol*_*cks 12 bash ncurses readline
我想我以前已经注意到这一点,但从未想太多;现在我很好奇。
> ldd /bin/bash
linux-vdso.so.1 => (0x00007fff2f781000)
libtinfo.so.5 => /lib64/libtinfo.so.5 (0x00007f0fdd9a9000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f0fdd7a5000)
libc.so.6 => /lib64/libc.so.6 (0x00007f0fdd3e6000)
/lib64/ld-linux-x86-64.so.2 (0x00007f0fddbf6000)
Run Code Online (Sandbox Code Playgroud)
libtinfo 是 ncurses 的一部分。这是一个 Fedora 系统,但它在 ubuntu 上是一样的,我注意到在 raspbian(一个 debian 变体)上它也链接到 libncurses 本身。
这是什么原因?我认为 bash 所做的一切都可以用 libreadline 来完成(奇怪的是,它没有链接到)。这只是一个替代品吗?
Sté*_*las 18
如果您运行bash
为:
LD_DEBUG=bindings bash
Run Code Online (Sandbox Code Playgroud)
在 GNU 系统上,并bash.*tinfo
在该输出中使用grep for ,您将看到如下内容:
797: binding file bash [0] to /lib/x86_64-linux-gnu/libtinfo.so.5 [0]: normal symbol `UP'
797: binding file bash [0] to /lib/x86_64-linux-gnu/libtinfo.so.5 [0]: normal symbol `PC'
797: binding file bash [0] to /lib/x86_64-linux-gnu/libtinfo.so.5 [0]: normal symbol `BC'
797: binding file bash [0] to /lib/x86_64-linux-gnu/libtinfo.so.5 [0]: normal symbol `tgetent'
797: binding file bash [0] to /lib/x86_64-linux-gnu/libtinfo.so.5 [0]: normal symbol `tgetstr'
797: binding file bash [0] to /lib/x86_64-linux-gnu/libtinfo.so.5 [0]: normal symbol `tgetflag'
Run Code Online (Sandbox Code Playgroud)
您可以从输出确认nm -D /bin/bash
是bash
使用来自TINFO的符号。
为这些符号中的任何一个带来手册页阐明了它们的用途:
$ man tgetent
NAME
PC, UP, BC, ospeed, tgetent, tgetflag, tgetnum, tgetstr, tgoto, tputs -
direct curses interface to the terminfo capability database
Run Code Online (Sandbox Code Playgroud)
基本上,bash
更可能的是它的readline
(libreadline 静态链接在)编辑器中,使用这些来查询 terminfo 数据库以了解终端功能,以便它可以正确运行其行编辑器(发送正确的转义序列并正确识别按键)在任何终端。
至于为什么 readline 是静态链接的bash
,你必须记住,readline
是bash
由同一个人开发的,并且包含在bash
.
可以构建bash
与系统的已安装 链接libreadline
,但前提是该版本是兼容版本,并且这不是默认值。您需要configure
在编译时使用--with-installed-readline
.