backslashes in output of command substitution trigger GLOB
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
Re: backslashes in output of command substitution trigger GLOB
> On Oct 10, 2020, at 10:23 PM, idal...@idallen.ca wrote: > > 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. Sounds like a problem that will be addressed in 5.1 (https://lists.gnu.org/archive/html/bug-bash/2020-09/msg00019.html): > From: Chet Ramey > Subject: Bash-5.1-beta available > Date: September 10, 2020 at 10:17:19 AM EDT > To: bug-bash@gnu.org > Cc: chet.ra...@case.edu > Reply-To: chet.ra...@case.edu > > [...] > > This release fixes several outstanding bugs in bash-5.0 and introduces > several new features. The most significant change is a return to the > bash-4.4 behavior of not performing pathname expansion on a word that > contains backslashes but does not contain any unquoted globbing special > characters. This comes after a long POSIX discussion that resulted in a > change to the standard. > > [...] > > There are a few incompatible changes between bash-5.0 and bash-5.1. The > change to pathname expansion means that words containing backslashes, but no > special globbing characters, will not undergo pathname expansion. While > the bash-5.0 behavior was POSIX-conformant, the change was not well-received. vq