0

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?

Pedro Gimeno
  • 2,837
  • 1
  • 25
  • 33

2 Answers2

1

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.

Hans Lub
  • 5,513
  • 1
  • 23
  • 43
  • Thanks. I may have found a bug, but I'm still not sure it's an rlwrap bug, and whatever the outcome, I'd like to know if there's a workaround for such a situations. I'm a bit surprised that setting a variable in a pipe didn't work. Either way, I'm going to help you narrow it down. – Pedro Gimeno Jan 07 '19 at 12:29
0

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.

Pedro Gimeno
  • 2,837
  • 1
  • 25
  • 33