bug-bash
[Top][All Lists]
Advanced

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

backslashes in output of command substitution trigger GLOB


From: idallen
Subject: backslashes in output of command substitution trigger GLOB
Date: Sat, 10 Oct 2020 22:23:04 -0400 (EDT)

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fdebug-prefix-map=/build/bash-a6qmCk/bash-5.0=. 
-fstack-protector-strong -Wformat -Werror=format-security -Wall 
-Wno-parentheses -Wno-format-security
uname output: Linux idallen-oak 5.4.0-48-generic #52-Ubuntu SMP Thu Sep 10 
10:58:49 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.0
Patch Level: 17
Release Status: release

Description:
    If a word in the output of a command substitution contains a
    backslash, and the word (without backslash) happens to match a
    file name, the shell will replace the word with the file name.
    The backslashes will disappear.  If the word doesn't match a file
    name, the backslashes are preserved.

    Backslashes are not GLOB characters.  This matching should not happen.

    Turn on "shopt -s failglob".  Now, if a word in the output of a
    command substitution contains a backslash, and the word (without
    the backslash) doesn't match a filename, bash gives a GLOB "no
    match" error.  Backslashes are not GLOB characters.  This error
    should not happen.

    I noticed this bug because many of the bash completion scripts don't
    work for me because I use "shopt -s failglob" in my .bashrc and many
    of the completion scripts don't properly quote to protect against
    GLOB expansion.  I saw a "no match" error for a word that didn't
    have any GLOB characters in it, but did have a backslash.  Bug found.

Repeat-By:

    # Run "bash --norc" and enter an empty directory and do these things below.
    # The first section runs without failglob; the second section with.
    # The unexpected output is flagged with "NOT EXPECTED" below.

    bash-5.0$ shopt -u failglob
    bash-5.0$ echo '\a' >/tmp/foo  # create a file with just \a in it
    bash-5.0$ echo \a
    a
    bash-5.0$ echo $(echo '\a')
    \a
    bash-5.0$ echo $(cat /tmp/foo)
    \a
    bash-5.0$ touch a
    bash-5.0$ echo $(echo '\a')
    a                                        <=== NOT EXPECTED!
    bash-5.0$ echo $(cat /tmp/foo)
    a                                        <=== NOT EXPECTED!
    bash-5.0$ echo $(echo '\a\b\c\d\e\f')
    \a\b\c\d\e\f
    bash-5.0$ touch abcdef
    bash-5.0$ echo $(echo '\a\b\c\d\e\f')
    abcdef                                   <=== NOT EXPECTED

    bash-5.0$ shopt -s failglob
    bash-5.0$ rm *
    bash-5.0$ echo \a
    a
    bash-5.0$ echo $(echo '\a')
    bash: no match: \a                       <=== NOT EXPECTED!
    bash-5.0$ echo $(cat /tmp/foo)
    bash: no match: \a                       <=== NOT EXPECTED!
    bash-5.0$ touch a
    bash-5.0$ echo $(echo '\a')
    a                                        <=== NOT EXPECTED!
    bash-5.0$ echo $(cat /tmp/foo)
    a                                        <=== NOT EXPECTED!
    bash-5.0$ echo $(echo '\a\b\c\d\e\f')
    bash: no match: \a\b\c\d\e\f             <=== NOT EXPECTED!
    bash-5.0$ touch abcdef
    bash-5.0$ echo $(echo '\a\b\c\d\e\f')
    abcdef                                   <=== NOT EXPECTED
    



reply via email to

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