Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #15301 > unrolled thread

Re: Setting nullglob causes variables containing backslashes to be expanded to an empty string

Started byGreg Wooledge <wooledg@eeg.ccf.org>
First post2019-08-06 16:00 -0400
Last post2019-08-06 21:42 +0100
Articles 4 — 2 participants

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Setting nullglob causes variables containing backslashes to be expanded to an empty string Greg Wooledge <wooledg@eeg.ccf.org> - 2019-08-06 16:00 -0400
    Re: Setting nullglob causes variables containing backslashes to be expanded to an empty string Stephane Chazelas <stephane.chazelas@gmail.com> - 2019-08-06 21:28 +0100
      Re: Setting nullglob causes variables containing backslashes to be expanded to an empty string Stephane Chazelas <stephane.chazelas@gmail.com> - 2019-08-06 21:39 +0100
        Re: Setting nullglob causes variables containing backslashes to be expanded to an empty string Stephane Chazelas <stephane.chazelas@gmail.com> - 2019-08-06 21:42 +0100

#15301 — Re: Setting nullglob causes variables containing backslashes to be expanded to an empty string

FromGreg Wooledge <wooledg@eeg.ccf.org>
Date2019-08-06 16:00 -0400
SubjectRe: Setting nullglob causes variables containing backslashes to be expanded to an empty string
Message-ID<mailman.968.1565121631.1985.bug-bash@gnu.org>
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.

For the record,   echo $a   is *not* a sane way to see the contents of
your variable.   printf %s\\n "$a"   is the safest.   echo "$a"   would
be marginally acceptable in some cases.  Unquoted $a is a bad idea, which
may explain why it didn't receive enough testing to uncover whatever
this is.  No sane person would do it.

[toc] | [next] | [standalone]


#15302

FromStephane Chazelas <stephane.chazelas@gmail.com>
Date2019-08-06 21:28 +0100
Message-ID<20190806202819.3zpyixfptmqrdvgr@chaz.gmail.com>
In reply to#15301
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 austingroup mailing list (and has
been discussed here before as well).

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).

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

-- 
Stephane

[toc] | [prev] | [next] | [standalone]


#15303

FromStephane Chazelas <stephane.chazelas@gmail.com>
Date2019-08-06 21:39 +0100
Message-ID<20190806203955.nba45vjkmx5bu2a6@chaz.gmail.com>
In reply to#15302
2019-08-06 21:28:20 +0100, Stephane Chazelas:
[...]
> That is being discussed on the austingroup mailing list (and has
> been discussed here before as well).
> 
> 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).
[...]

with the current head of the  devel branch, that behaviour can
be disabled by turning off the posixglob option (I still do hope
that POSIX will give up on this silly idea).

$ a='\x30' ./bash +O posixglob -O nullglob -c 'printf "%s\n" $a'
\x30
$ a='\x30' ./bash -O nullglob -c 'printf "%s\n" $a'

$ 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

[toc] | [prev] | [next] | [standalone]


#15305

FromStephane Chazelas <stephane.chazelas@gmail.com>
Date2019-08-06 21:42 +0100
Message-ID<20190806204248.lbe57vapurinrh5b@chaz.gmail.com>
In reply to#15303
2019-08-06 21:39:55 +0100, Stephane Chazelas:
[...]
> with the current head of the  devel branch, that behaviour can
> be disabled by turning off the posixglob option (I still do hope
> that POSIX will give up on this silly idea).
> 
> $ a='\x30' ./bash +O posixglob -O nullglob -c 'printf "%s\n" $a'
> \x30
> $ a='\x30' ./bash -O nullglob -c 'printf "%s\n" $a'
> 

Sorry, there was a missing

$ touch x30

there.

> $ a='\x30' ./bash -O nullglob -c 'printf "%s\n" $a'
> x30

[toc] | [prev] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web