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

NOSHWORDSPLIT problem??



Hi,

I've been trying to wean myself from using double quotes around
everything since my understanding was that with SHWORDSPLIT unset this
was no longer needed.  However, there does seem to be a case when you
still get screwed, and I'm wondering if that is intentional or a bug
in zsh.  You still run into trouble if you have a variable containing
the empty string.

First some preliminaries:

phl% /bin/zsh-4.0.6 -f
phl% 
phl% echo $ZSH_VERSION
4.0.6
phl% unsetopt shwordsplit
phl% function count () { echo $# }
phl% 
phl% w="foo"
phl% x="bar baz"
phl% y=" space-on-either-end "
phl% z=""

When $z is not enclosed in double quotes, the empty string does not
make it into the array a:

phl% a=( $w $x $y $z )
phl% echo $#a
3
phl% count $a[@]                                
3
phl% for v in $a[@] ; do echo "v= \"$v\"" ; done
v= "foo"
v= "bar baz"
v= " space-on-either-end "

If $z is enclosed in double quotes, the empty string does make it into
the array a, but I further need to enclose expansions of the form
$a[@] in double quotes to have it not be elided:

phl% a=( $w $x $y "$z" )
phl% echo $#a                                   
4
phl% count $a[@]                                
3
phl% for v in $a[@] ; do echo "v= \"$v\"" ; done
v= "foo"
v= "bar baz"
v= " space-on-either-end "
phl% for v in "$a[@]" ; do echo "v= \"$v\"" ; done
v= "foo"
v= "bar baz"
v= " space-on-either-end "
v= ""

This seems pretty broken to me, because I still need to use all those
silly double quotes that NOSHWORDSPLIT is supposed to avoid.

thanks,
Greg



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