Pedro Gimeno
Pedro Gimeno

Reputation: 3125

Ctrl-C in a rlwrap command substitution stops echo

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?

Upvotes: 0

Views: 791

Answers (2)

Pedro Gimeno
Pedro Gimeno

Reputation: 3125

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.

Upvotes: 0

Hans Lub
Hans Lub

Reputation: 5678

Your use of rlwrap within a $(...) construct is correct. That you can do this is part of rlwrap's "transparency": whatever works with <command> should also work with rlwrap <command>.

I cannot reproduce the problem on any of my systems.

This means you found a bug. You already posted an issue on the rlwrap Github site.

Edit: straceing rlwrap on two systems, of which only one displays the bug, doesn't show any significant differences, so we conclude that this is probably not a rlwrap problem.

Upvotes: 1

Related Questions