for loop goes to stopped job when Ctrl+C is pressed

2022-12-17 Thread ks1322 ks1322
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -O2 -flto=auto -ffat-lto-objects -fexceptions -g
-grecord-gcc-switches -pipe -Wall -Werror=format-security
-Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS
-specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -fstack-prote>
uname output: Linux yourdomain.com 6.0.12-300.fc37.x86_64 #1 SMP
PREEMPT_DYNAMIC Thu Dec 8 16:58:47 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-redhat-linux-gnu

Bash Version: 5.2
Patch Level: 9
Release Status: release

Description:
When for loop output is piped to less and Ctrl+C is pressed, bash creates
unexpected stopped job

Repeat-By:
1. Create a log file with the command:
yes | head -n 100 > log
2. Pipe log output to less this way:
for i in log; do cat $i; done | less
3. Press Ctrl+C in less
4. Quit from less with q

Result:
unexpected stopped job is created
[1]+  Stopped for i in log;
do
cat $i;
done | less

There is no such issue in zsh


Re: compgen stops processing backslashes after any call to bind

2022-12-17 Thread of1

On 16/12/2022 23:18, Chet Ramey wrote:



Your arguments undergo word expansion, including double-quote processing,
before compgen sees them. 


Thank you very much for your thorough explanation. I also take this
opportunity to thank you for
https://lists.gnu.org/archive/html/bug-bash/2022-11/msg00035.html
and I thank Koichi too.

I had seen, using set -x, that backslashes were given special
treatment but, in my naive view, I didn't grasp that was a consequence
of a larger problem.

So I have a function that works now. Maybe someone will have a wiser
solution.


#!/usr/bin/env bash

[[ "$(find /tmp/ -maxdepth 1 -type d -name "DirA")" ]] && exit 2
mkdir -p /tmp/Dir\\A/dirB/dir\\C/dirD/
touch /tmp/Dir\\A/dirB/dir\\C/dirD/fileA

set -o emacs

f_comp() {
   local COMP CPR="${1%\/*}" CPO="${1##*\/}"
   #echo 1>&2; set -x
   COMP="$(compgen -f "${CPR//\\/}${1:+/}${CPO//\\/}")"
   set +x
   CPR="${COMP%\/*}" CPO="${COMP##*\/}"
   printf '%s' "${CPR///\\}${1:+/}$CPO"
}

bind -X

for DF in "/tmp/Dir" "/tmp/Dir\\A" "/tmp/Dir\\A/" "/tmp/Dir\\A/dir\\" \
  "/tmp/Dir\\A/dirB" "/tmp/Dir\\A/dirB/" \
  "/tmp/Dir\\A/dirB/dir\\" \
  "/tmp/Dir\\A/dirB/dir\\C/dir" \
  "/tmp/Dir\\A/dirB/dir\\C/dirD/file"; do
   printf '%s\n' "$(( ++COUNT )) $DF  >>>  $(f_comp "$DF")"
done

rm -rf /tmp/Dir\\A/


### Output:
1 /tmp/Dir  >>>  /tmp/Dir\A
2 /tmp/Dir\A  >>>  /tmp/Dir\A
3 /tmp/Dir\A/  >>>  /tmp/Dir\A/dir\\B
4 /tmp/Dir\A/dir\  >>>  /tmp/Dir\A/dir\\B
5 /tmp/Dir\A/dir\\B  >>>  /tmp/Dir\A/dir\\B
6 /tmp/Dir\A/dir\\B/  >>>  /tmp/Dir\A/dir\\B/dir\\\C
7 /tmp/Dir\A/dir\\B/dir\\\  >>>  /tmp/Dir\A/dir\\B/dir\\\C
8 /tmp/Dir\A/dir\\B/dir\\\C/dir  >>>  /tmp/Dir\A/dir\\B/dir\\\C/dirD
9 /tmp/Dir\A/dir\\B/dir\\\C/dirD/file  >>> 
/tmp/Dir\A/dir\\B/dir\\\C/dirD/fileA





Segfault with set -o emacs in -c

2022-12-17 Thread Harald van Dijk

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnux32
Compiler: clang -mx32
Compilation CFLAGS: -O2
uname output: Linux framework 6.0.12 #1 SMP PREEMPT_DYNAMIC @1664744947 x86_64 
GNU/Linux
Machine Type: x86_64-pc-linux-gnux32

Bash Version: 5.2
Patch Level: 12
Release Status: release

Description:
bash segfaults if 'set -o emacs' is run when it is executing a command 
string.

gdb shows:

Program received signal SIGSEGV, Segmentation fault.
0x002c64fa in parse_and_execute (string=string@entry=0x3553a0 "set -o emacs", 
from_file=, flags=flags@entry=20) at /h/bash-5.2/builtins/evalstring.c:341
341  while (*(bash_input.location.string) || parser_expanding_alias 
())
(gdb) p bash_input.location.string
$1 = 0x0

This is ultimately because:

static int
set_edit_mode (on_or_off, option_name)
 int on_or_off;
 char *option_name;
{
  ...
  if (interactive)
with_input_from_stdin ();
  ...

The assumption here, that if (interactive), input is coming from stdin, 
does not hold when running bash -ic.

Repeat-By:
bash -ic 'set -o emacs'