[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

compgen stops processing backslashes after any call to bind

From: Fabien Orjollet
Subject: compgen stops processing backslashes after any call to bind
Date: Thu, 15 Dec 2022 01:55:45 +0100

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wall uname output: Linux debtest 6.0.0-5-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.0.10-2 (2022-12-01) x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

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

        compgen's behavior regarding backslash processing is altered by
        any call to bind.
        Therefore, file and directory names containing a backslash are
        not completed once bind has been called.
        Below is an example to reproduce the issue followed by its

#!/usr/bin/env bash

[[ "$(find /tmp/ -maxdepth 1 -type d -name "Dir\\\\*")" ]] && exit 2
mkdir /tmp/Dir{\\A,\\\\B,\\\\\\C}
touch /tmp/Dir\\A/file\\A /tmp/Dir\\\\B/file\\\\B /tmp/Dir\\\\\\C/file\\\\\\C

set -o emacs

f_comp() {
   case "$1" in
      1) compgen -f "$2";;
      2) compgen -o dirnames -f "$2";;

for DF in "/tmp/Dir" "/tmp/Dir\\A" "/tmp/Dir\\\\B" "/tmp/Dir\\\\\\" \
          "/tmp/Dir\\A/" "/tmp/Dir\\\\B/" "/tmp/Dir\\\\\\C/" \
          "/tmp/Dir\\A/file"; do
   echo "$(( ++COUNT )) compgen1  $DF  before bind>>> $(f_comp 1 "$DF")"
   echo "$COUNT compgen2  $DF  before bind>>> $(f_comp 2 "$DF")"
echo; COUNT=0

bind -X

for DF in "/tmp/Dir" "/tmp/Dir\\A" "/tmp/Dir\\\\B" "/tmp/Dir\\\\\\" \
          "/tmp/Dir\\A/" "/tmp/Dir\\\\B/" "/tmp/Dir\\\\\\C/" \
          "/tmp/Dir\\A/file"; do
   echo "$(( ++COUNT )) compgen1  $DF  after bind>>> $(f_comp 1 "$DF")"
   echo "$COUNT compgen2  $DF  after bind>>> $(f_comp 2 "$DF")"

rm -rf /tmp/Dir\\*

### Output:
1 compgen1  /tmp/Dir  before bind>>> /tmp/Dir\A
1 compgen2  /tmp/Dir  before bind>>> /tmp/Dir\A

2 compgen1  /tmp/Dir\A  before bind>>> /tmp/Dir\A
2 compgen2  /tmp/Dir\A  before bind>>> /tmp/Dir\A

3 compgen1  /tmp/Dir\\B  before bind>>> /tmp/Dir\\B
3 compgen2  /tmp/Dir\\B  before bind>>> /tmp/Dir\\B

4 compgen1  /tmp/Dir\\\  before bind>>> /tmp/Dir\\\C
4 compgen2  /tmp/Dir\\\  before bind>>> /tmp/Dir\\\C

5 compgen1  /tmp/Dir\A/  before bind>>> /tmp/Dir\A/file\A
5 compgen2  /tmp/Dir\A/  before bind>>> /tmp/Dir\A/file\A

6 compgen1  /tmp/Dir\\B/  before bind>>> /tmp/Dir\\B/file\\B
6 compgen2  /tmp/Dir\\B/  before bind>>> /tmp/Dir\\B/file\\B

7 compgen1  /tmp/Dir\\\C/  before bind>>> /tmp/Dir\\\C/file\\\C
7 compgen2  /tmp/Dir\\\C/  before bind>>> /tmp/Dir\\\C/file\\\C

8 compgen1  /tmp/Dir\A/file  before bind>>> /tmp/Dir\A/file\A
8 compgen2  /tmp/Dir\A/file  before bind>>> /tmp/Dir\A/file\A

1 compgen1  /tmp/Dir  after bind>>> /tmp/Dir\A
1 compgen2  /tmp/Dir  after bind>>> /tmp/Dir\A

2 compgen1  /tmp/Dir\A  after bind>>>
2 compgen2  /tmp/Dir\A  after bind>>> /tmp/Dir\A

3 compgen1  /tmp/Dir\\B  after bind>>>
3 compgen2  /tmp/Dir\\B  after bind>>> /tmp/Dir\\B

4 compgen1  /tmp/Dir\\\  after bind>>> /tmp/Dir\A
4 compgen2  /tmp/Dir\\\  after bind>>> /tmp/Dir\A

5 compgen1  /tmp/Dir\A/  after bind>>>
5 compgen2  /tmp/Dir\A/  after bind>>>

6 compgen1  /tmp/Dir\\B/  after bind>>>
6 compgen2  /tmp/Dir\\B/  after bind>>>

7 compgen1  /tmp/Dir\\\C/  after bind>>>
7 compgen2  /tmp/Dir\\\C/  after bind>>>

8 compgen1  /tmp/Dir\A/file  after bind>>>
8 compgen2  /tmp/Dir\A/file  after bind>>>

reply via email to

[Prev in Thread] Current Thread [Next in Thread]