Bash – How to Change $TERMINFO in bashrc Script

bashreadlineterminal

I'm trying to set TERMINFO="$HOME/.terminfo" within my .bashrc script. The reason being is that my terminal isn't in the system terminfo location, and so I have its terminfo file in my home directory.
The problem here is that the change doesn't take effect for the current shell, only subshells. I'm guessing it's because readline is being initialized before bash reads the .bashrc file.

So is there any way to solve this issue? Perhaps some way to re-initialize readline so the changed $TERMINFO takes effect?
I'm trying to avoid doing an exec bash after setting it, as then I have to make sure I don't end up in a re-exec loop, and that's just ugly (though doing exec bash after setting it does work).

EDIT: This is not a issue running the script. I know for a fact the .bashrc script is being run and that $TERMINFO is being set. Running echo $TERMINFO after the shell has finished starting shows the correct value.

EDIT2: It appears this might be bash or readline library version related. I can't duplicate the issue with bash-4.2.20 and readline-6.2_p1, but I can with bash-3.2 and readline-5.1.3.

"No" is an acceptable answer if it's not possible. But it would be nice to know what's going on that causes the answer to be "no".

Best Answer

So after digging around some more, I found what's going on. RHEL5's build of bash doesn't use terminfo at all (why, who knows, it's Red Hat), it uses termcap. However, there is apparently another bash on the box which does use terminfo. This is why subshells and re-execing would work, as they would use the other bash, not the default one. I feel stupid for not noticing this.

This can be determined from comparing 2 commands:

# ldd "$BASH"
    linux-vdso.so.1 =>  (0x00007fff4f1fd000)
    libtermcap.so.2 => /lib64/libtermcap.so.2 (0x0000003e0bc00000)
    libdl.so.2 => /lib64/libdl.so.2 (0x0000003e07000000)
    libc.so.6 => /lib64/libc.so.6 (0x0000003e06c00000)
    /lib64/ld-linux-x86-64.so.2 (0x0000003e06800000)

# ldd `which bash`
    linux-vdso.so.1 =>  (0x00007fff643fd000)
    libncurses.so.5 => /usr/lib64/libncurses.so.5 (0x0000003e0d800000)
    libdl.so.2 => /lib64/libdl.so.2 (0x0000003e07000000)
    libc.so.6 => /lib64/libc.so.6 (0x0000003e06c00000)
    /lib64/ld-linux-x86-64.so.2 (0x0000003e06800000)

Noticing that one is linked against libtermcap, and the other against libncurses.

I should have specified that I was using RHEL here, as that's apparently the critical factor. Why they use termcap when pretty much everyone else in the world has abandoned it makes no sense, but there it is.

Related Question