Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Word splitting in zsh



On Feb 9, 12:23pm, Deborah Ariel Pickett wrote:
}
} I've come across this little problem in zsh when I run it under
} setopt SHWORDSPLIT (not that this is something I normally do).

There's definitely some kind of bug here.

zagzig% echo $ZSH_VERSION
3.0.8
zagzig% set "a1 a2 a3" b c
zagzig% print -l ${1+"$@"}
a1 a2 a3
b
c
zagzig% setopt shwordsplit
zagzig% print -l ${1+"$@"}
a1
a2
a3
b
c
zagzig% 

Well, that's not quite right, but 3.1.9-dev-8 is even worse:

zagzig% echo $ZSH_VERSION 
3.1.9-dev-8
zagzig% set "a1 a2 a3" b c
zagzig% print -l ${1+"$@"}
a1 a2 a3 b c						<-- Yipes!
zagzig% setopt shwordsplit
zagzig% print -l ${1+"$@"}
a1
a2
a3
b
c
zagzig% 

It wasn't always so:

zagzig% echo $VERSION
zsh 2.4.306 beta
zagzig% setopt shwordsplit
zagzig% set "a1 a2 a3" b c
zagzig% print -l ${1+"$@"}
a1 a2 a3
b
c
zagzig% 

I don't know exactly when this bug was introduced, though.

} bruce ~ % args "$@"
} # Acceptable, but Bourne sh would print a single blank entry here, since
} # there's a pair of quotes.

Actually, that's not quite true.  Some versions of Bourne sh expand "$@"
to the empty string, and some expand it to no string at all.  The reason
for the ${1+"$@"} hack in many shell scripts is so that you don't have
to care which flavor of Bourne shell you have.  Zsh has always tried to
be in the latter camp, e.g.,

zagzig% print -l X "" X
X

X
zagzig% print -l X "$@" X
X
X
zagzig% 


-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



Messages sorted by: Reverse Date, Date, Thread, Author