Path: csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail From: Stephane Chazelas Newsgroups: gnu.bash.bug Subject: Re: Setting nullglob causes variables containing backslashes to be expanded to an empty string Date: Wed, 7 Aug 2019 07:27:50 +0100 Lines: 63 Approved: bug-bash@gnu.org Message-ID: References: <5202404D-4B1E-4627-9FDE-2E0C5608A5B7@outlook.com> <20190806200021.GK1218@eeg.ccf.org> <20190807062750.igdwgxqtmypm44qr@chaz.gmail.com> NNTP-Posting-Host: lists.gnu.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: usenet.stanford.edu 1565159418 27718 209.51.188.17 (7 Aug 2019 06:30:18 GMT) X-Complaints-To: action@cs.stanford.edu To: bug-bash@gnu.org Envelope-to: bug-bash@gnu.org X-Injected-Via-Gmane: http://gmane.org/ User-Agent: NeoMutt/20171215 Content-Disposition: inline In-Reply-To: <20190806200021.GK1218@eeg.ccf.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 195.159.176.226 X-BeenThere: bug-bash@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Bug reports for the GNU Bourne Again SHell List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <20190807062750.igdwgxqtmypm44qr@chaz.gmail.com> X-Mailman-Original-References: <5202404D-4B1E-4627-9FDE-2E0C5608A5B7@outlook.com> <20190806200021.GK1218@eeg.ccf.org> Xref: csiph.com gnu.bash.bug:15306 [re-post via gmane as the usenet interface seems not to work again. My posts can be seen at https://groups.google.com/forum/#!topic/gnu.bash.bug/0JgBRq_778o but were apparently not forwarded to the mailing list] 2019-08-06 16:00:21 -0400, Greg Wooledge: > On Tue, Aug 06, 2019 at 06:18:27PM +0000, Mohamed Akram wrote: > > Bash version: GNU bash, version 5.0.7(1)-release (x86_64-apple-darwin18.5.0) > > > > Example: > > > > shopt -s nullglob > > a='\x30' > > echo $a > > > > Expected output: > > > > \x30 > > > > Actual output: > > > > Also happens in bash 5.0 on Debian GNU/Linux. It does not happen in > bash 4.4 or earlier (I tried back to 3.2) on the same machine. [...] That is being discussed on the austin-group mailing list (and has been discussed here before as well IIRC). The idea is that in 5.0, \ became a globbing quoting operator. So with nullglob, the \x30 expands to x30 when there's a file called x30 in the current directory and nothing if not. That is by design and was supported until relatively recently by some Austin Group people (the guys behind POSIX). That's not done by any other major shell. See http://austingroupbugs.net/view.php?id=1234 and the very long discussions that follow on the mailing list: See for instance https://www.mail-archive.com/austin-group-l@opengroup.org/msg04237.html As seen there, with the current head of the devel branch, that behaviour can be disabled by turning off the posixglob option. $ a='\x30' ./bash +O posixglob -O nullglob -c 'printf "%s\n" $a' \x30 $ a='\x30' ./bash -O nullglob -c 'printf "%s\n" $a' $ touch x30 $ a='\x30' ./bash -O nullglob -c 'printf "%s\n" $a' x30 In any case, yes, do remember to quote your variable expansions and not use echo for arbitrary data. -- Stephane