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

A bug or improperly formatted script



ZSH_VERSION:  4.3.17, 5.0.8, 5.2, 5,3.1

While doing a search, unrelated, I found the following on the
zsh-lovers(1) man page:

# Count the number of directories on the stack
  $ print $((${${(z)${(f)"$(dirs -v)"}[-1]}[1]} + 1)) #...

I was surprised the first time I tried it I got "-2" as the output.

Modifying the script to

$ print $((${(z)${(fO)"$(dirs -v)"}[1][1]} + 1))

returned "1" as expected.  "dirs -v" outputs "0      ~".  Stripping the

expression from the original script, outputs, "~" whereas the modified

script returns "0".  It would appear as if the original script is returning

a scalar when the stack only has one entry and an array when the

stack has 2 or more entries.  Tested another, somewhat unrealistic,

case with a directory "-" under the home directory "0      ~/-", the

output was "-1" for the original script.

So, is this a bug, or scripting?  Hard to believe someone

hadn't run across something like this before.


Sincerely,

Jim

Sorry if this email looks strange, gmail, as least while composing,

looked really strange after a cut/paste dropped in some fixed font

and line spacing went nuts.


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