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


Groups > gnu.bash.bug > #14379

Re: Empty ""s in ARG in ${x:+ARG} expand to no words instead of the empty word if prepended/appended with space

From Bob Proulx <bob@proulx.com>
Newsgroups gnu.bash.bug
Subject Re: Empty ""s in ARG in ${x:+ARG} expand to no words instead of the empty word if prepended/appended with space
Date 2018-07-21 11:16 -0600
Message-ID <mailman.3985.1532193386.1292.bug-bash@gnu.org> (permalink)
References <3d5b8d4b-b77e-2486-b45b-ca733e4d0ca0@redhat.com> <20180720223753294160030@bob.proulx.com> <2fe93203-93fd-2a97-ff54-7cb748294640@case.edu>

Show all headers | View raw


Chet Ramey wrote:
> Bob Proulx wrote:
> > Denys Vlasenko wrote:
> >> $ f() { for i; do echo "|$i|"; done; }
> >> $ x=x
> >> $ e=
> >> $ f ${x:+ ""}
> >> ^^^^^^^^^^^ prints nothing, bug?
> >>
> >> $  ${x:+"" }
> >> ^^^^^^^^^^^ prints nothing, bug?
> > 
> > Insufficient quoting.  That argument should be quoted to avoid the
> > whitespace getting stripped.  (Is that during word splitting phase
> > using the IFS?  I think so.)
> 
> Even if the whitespace gets stripped out, the quoted null string should
> result in an empty argument. Different shells are inconsistent about this,
> but I believe that if word splitting occurs, the empty string (or "$e",
> anything that expands to an empty string) should result in a null word.

Gotcha.  Thanks!

And further testing confirms the inconsistent shells.  bash and ksh
both seem to be the outliers in different ways in terms of behavior.
dash and zsh seem to be consistent and correct in this.

Bob

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

Re: Empty ""s in ARG in ${x:+ARG} expand to no words instead of the empty word if prepended/appended with space Bob Proulx <bob@proulx.com> - 2018-07-21 11:16 -0600

csiph-web