On Wed, Jul 26, 2023 at 2:23 PM Grisha Levit <grishale...@gmail.com> wrote: > If the last character read was an (unescaped) backslash, store it as > such instead of as a CTLESC. Avoids: > > $ printf '\\' | { read; echo "${REPLY@Q}"; } > bash: DEBUG warning: dequote_string: string with bare CTLESC > $'\001'
Sorry that was wrong, the CTLESC should just be removed. Much simpler patch below. --- diff --git a/builtins/read.def b/builtins/read.def index 5b2621fe..ce5bcc38 100644 --- a/builtins/read.def +++ b/builtins/read.def @@ -751,11 +751,11 @@ read_builtin (WORD_LIST *list) if (pass_next) { pass_next = 0; - if (c == '\n') + if (c == '\n' || c == '\0') { if (skip_ctlesc == 0 && i > 0) i--; /* back up over the CTLESC */ - if (interactive && input_is_tty && raw == 0) + if (interactive && input_is_tty && raw == 0 && c == '\n') print_ps2 = 1; } else @@ -825,6 +825,11 @@ add_char: if (nchars > 0 && nr >= nchars) break; } + + if (pass_next && skip_ctlesc == 0) + i--; /* back up over the CTLESC */ + if (skip_ctlnul && saw_escape && i == 1 && input_string[0] == CTLNUL) + saw_escape = 0; /* Avoid dequoting bare CTLNUL */ input_string[i] = '\0'; check_read_timeout ();