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

3.1.9-dev-6: bug or confusion?



Define these two functions:

function okay
{
  emulate -L zsh
  echo ${#${@:#-}}
  setopt localoptions xtrace
  (( ${#${@:#-}} ))
}

function broken
{
  emulate -L zsh
  echo ${#${@#-}}
  setopt localoptions xtrace
  (( ${#${@#-}} ))
}

Notice that the only difference between these two functions is that
one uses :# (match whole word) and the other uses # (match beginning
of word) as applied to each element of $@.

Then run

zsh% okay -

You get the expected output:

0
+okay:5> ((  0  ))

Now run

zsh% broken -

You get the unexpected (by me anyway) output:

0
+broken:5> ((  1  ))

Why would the value be 1 inside (( ... )) and 0 outside in the second
case but not in the first?  Does it have something to do with an empty
string being counted as a word in one case but not the other?  Is it a
bug?  If not, I'd be grateful if someone could explain this behavior.

--
E. Jay Berkenbilt (ejb@xxxxxx)  |  http://www.ql.org/q/



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