I've got a bash script that would be nicer if when I prompt the user, rather than just asking for input, if it provided a line that the user could edit (but a full text editor would be overkill, it's only one line)
What tool provides this?
dialog
's inputbox is almost right, but I'd rather it didn't paint the whole screen.
The "read" built-in can do editing, using the Readline library, if you give it the "-e" flag:
If you don't mind using perl, you can use Term::Readline
There is also a readline() implementation in C; and probably in other languages. I don't know bash's interface for readline
perldoc Term::Readline
reproduced below, note sample script
In zsh, you have
vared
:and the cursor is then at the end of the wibble, you can edit as you like and when you press enter, you've defined the new value of
foo
.in bash,
notice the \r (carriage return) in the echo. The bracketee voodoo in the last line prints the reply plus the leftover part of the input that you did not erase.
its not ideal - you basicly overwrite the input var, you dont really edit it.
$2c, *-pike