bug-bash
[Top][All Lists]
Advanced

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

Re: Empty ""s in ARG in ${x:+ARG} expand to no words instead of the empt


From: Bob Proulx
Subject: Re: Empty ""s in ARG in ${x:+ARG} expand to no words instead of the empty word if prepended/appended with space
Date: Sat, 21 Jul 2018 11:16:17 -0600
User-agent: Mutt/1.10.1 (2018-07-13)

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



reply via email to

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