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

treatment of empty strings - why is this not a bug?



It's so nice that zsh doesn't do splitting on unquoted parameter
expansions:

[~] greg@lwm| zsh -f
lwm% function count () { echo $# }
lwm% a=( "a b" "c d" )
lwm% echo $#a[@]
2
lwm% count $a[@]
2
lwm% count "$a[@]"
2

however, it does silently drop empty strings:

lwm% a=( "" "" "" )
lwm% echo $#a[@] 
3
lwm% count $a[@]
0
lwm% count "$a[@]"
3

which means you still have to use all those quotes anyway.

I just don't understand why there should be any distinction
between the splitting and dropping of empty strings.

And even using quotes, zsh's treatment of empty strings here
seems very inconsistent:

lwm% x=::: && for v in "${(s-:-)x}" ; do echo "v= =>$v<=" ; done
v= =><=
v= =><=
lwm% x=:a:b: && for v in "${(s-:-)x}" ; do echo "v= =>$v<=" ; done 
v= =><=
v= =>a<=
v= =>b<=
v= =><=

thanks,
Greg



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