I'm using something like this in a script:
REPLY=$(rlwrap head -n 1)
Actually with more options but that suffices to reproduce the issue. It works perfectly for my purposes... as long as I don't press Ctrl-C to quit. If I do, input echo stops on the terminal and the only way I've found to restore it is to blindly type reset
.
The -I
flag didn't help. I also tried this:
rlwrap head -n 1 | REPLY=$(cat)
but then REPLY wasn't set when I pressed Enter. I've tried in both bash and dash, with identical results EDIT: Sorry, due to a typo on the shebang, dash was not being executed. It works correctly in dash.
How can I set a variable to the output of rlwrap
and be able to interrupt without losing input echo? Also out of curiosity, does anyone know what's going on here?
I was wrong about dash. It actually works fine under dash, therefore my solution was to stop using bash-specific features in the script and switch it to dash.
Update: Later I found that using this as the shebang makes it work with bash too:
#!/bin/bash --noediting
which basically disables readline for bash.