3

I am trying to make some of my code bash 3.X compatible and I have a key-binding that utilizes READLINE_LINE inside its callback function. 3.0 versions of Bash don't supply the READLINE_LINE, so I need an alternative way to get at the currently typed, but unexecuted line. I think I need some simple code (C hopefully) to grab the currently typed but unexecuted command from a Bash terminal and print it out to stdout (I'll capture it from there). My function will then manipulate it and then put it back (I can do this already)

I've explored Readline, and looked at command completion neither of those seem to be what I need. I've spent many hours reading about tty and readline and am at my whits end, the command is on the terminal so it must exist somewhere, right?

1 Answers1

2

I think you have a fundamental misconception of the division of labor between the terminal and the shell. The unexecuted command sits inside bash's memory, it isn't in the terminal. As soon as you type a character or function key, this information is sent to bash, and it's bash that manages edition commands, that updates the display, that provides completion, and so on. The readline library is part of bash. For more details, read What is the exact difference between a 'terminal', a 'shell', a 'tty' and a 'console'?

The upshot is that the code you want to write to manipulate the command has to sit inside bash: it needs to go beween one part of bash and another part of bash.

You can put an intermediate program between the terminal and bash, but if you do that, you'll lose the benefit of completion, and other niceties.

The READLINE_LINE variable was introduced in bash 4 because there's no way to do the same thing under bash 3. If what you're doing requires it, your best bet is to switch to bash 4 or zsh.