On 30/10/24 13:50, Lionel Élie Mamane wrote:
On Wed, 31 Jul 2024 16:44:04 +0200 Lionel Elie Mamane <lio...@mamane.lu>
wrote:
# STEP 1
$ touch a\$b
$ touch a\$c
$ ls
'a$b'  'a$c'
$ b=GOTYA

# STEP 2
# now, type
# ls <tab>
# the resulting display is
$ ls a$
# press <tab> again, the display is
$ ls a$
a$b  a$c
$ ls a$
# STEP 3
# now, type "b" to complete the filename, the display is
$ ls a$b
# type <enter>, message is:
ls: cannot access 'aGOTYA': No such file or directory

A fix for this issue is included in 5.2.32-1+b2.

I installed 5.2.32-1+b2 and still reproduced exactly the behaviour you
describe. I removed the ". /usr/share/bash-completion/bash_completion"
and ". /etc/bash_completion" from my ~/.bashrc, verified they are not
enabled (commented out) in /etc/bash.bashrc, opened a new terminal
emulator (which thus spawns a new bash), and I still reproduce exactly
the behaviour I describe.

I just double checked and this issue does not seem reproducible in unstable.

Setup:

    $ dpkg -l bash | grep bash
    ii  bash    5.2.32-1+b2  amd64   GNU Bourne Again SHell
    $ echo $BASH_VERSION
    5.2.32(1)-release
    $ complete -p # no output, bash-completion is not installed
    $ cd $(mktemp -d)
    $ touch 'a$b' 'a$c'
    $ ls
    'a$b'  'a$c'
    $ b=GOTYA

Tests:

    $ ls <TAB>
    $ ls a$
    $ ls a$<TAB><TAB>
    a$b a$c
    $ ls a$b<TAB>
    $ ls a\$b<ENTER>
    'a$b'

b is never expanded to GOTYA.

# type
# ls <tab>*

the result is:

$ ls a$*
ls: cannot access 'a': No such file or directory

but after a <tab>, adding '*' should expand to all filenames possible,
and her it does something else.

*<TAB> does not normally expand to all filenames.

     $ cd $(mktemp -d)
     $ touch aa ab ac bb
     $ ls a*<TAB>
     (no possible completion is shown)

The report was not about "*<TAB>" but about "<TAB>*".

The first <TAB> autocompletes to the common prefix of all files in the
directory. In your example that is the empty string, in my example
that is "a$" but with missing escaping of the "$".

Since what the <TAB> autocompletes to is supposed to be the common
prefix of all files in the directory, just typing "*<ENTER>" AFTER
having pressed "<TAB>" should end up being all files in the directory,
just as if <TAB> had not been pressed.

Sorry, I misread that line.

Nevertheless this issue does not seem to affect the version of bash in unstable:

    $ ls
    'a$b'  'a$c'
    $ ls <TAB>
    $ ls a$
    $ ls a$*<TAB>
    # nothing happens
    $ ls a$*<TAB><TAB>
    a$b  a$c
    $ ls a$*

$ echo a$b

then pressing <tab> should NOT escape the '$' since that is not what
was meant.

Why shouldn't it be escaped?

The user requested that the second word of the command line the string
"a" followed by the contents of the variable named b. Why would
pressing <TAB> change that to the string "a$b"?

You are mixing different levels: by default, the completion is done by readline before the line is evaluated by bash.

Bash configures readline in the way specified in the manual page under READLINE / Completing / complete (TAB):

Attempt to perform completion on the text before  point.   Bash
attempts  completion treating  the  text  as a variable (if the text
begins with $), username (if the text begins with ~), hostname (if
the text begins with @), or command  (including  aliases and
functions)  in  turn.  If none of these produces a match, filename
completion is attempted.
In this case the text does not start with $, so the default completion (filename completion) is attempted by readline.

Using `complete` it is possible to delegate the logic of the completion to bash functions a.k.a. "compspecs" (see "Programmable completion" in bash(1)). This is exploited by bash-completion.

If one desires the completion to work in a different way (for example evaluating possible variable before doing the completion), one can either write a different compspec, or modify one used by bash-completion, or file a bug with bash-completion to request a modification in how lines are completed in the presence of '$' characters.

Regards,

--
Gioele Barabucci

Reply via email to