* REPLY retains its integer attribute in glob qualifier functions
@ 2018-06-16 21:51 Stephane Chazelas
0 siblings, 0 replies; only message in thread
From: Stephane Chazelas @ 2018-06-16 21:51 UTC (permalink / raw)
To: Zsh hackers list
For
https://unix.stackexchange.com/questions/450207/how-to-sort-directories-using-permissions/450211#450211
I was defining a glob qualifier sorting function as:
zmodload zsh/stat
byperm() {
stat -LA REPLY +mode -- "$REPLY" &&
((REPLY = REPLY & 07777))
}
echo *(no+byperm)
And found that it was misbehaving.
$ ls
a.txt b.txt
$ echo *(o+byperm)
zsh: bad floating point constant
It turns out that ((REPLY = REPLY & 07777)) gives the "integer"
attribute to REPLY and it somehow fails when $REPLY is assigned
the next file name.
Note that it only happens if REPLY is first made an array (or
associative array or is unset).
This is OK:
$ unset REPLY; f() ((REPLY = 1)); echo *(o+f)
b.txt a.txt
(REPLY is not getting the integer attribute upon ((REPLY = 1)),
because it was already set as a non-integer scalar)
This is not:
$ unset REPLY; f() {REPLY=(); ((REPLY = 1))}; echo *(o+f)
zsh: bad floating point constant
a.txt b.txt
$ typeset -p REPLY
typeset -i REPLY=0
This time the ((REPLY = 1)) creates REPLY as a new scalar so
gets the integer attribute. Whatever attributes were given by
the function are retained for when zsh prepares $REPLY with the
next file as *input* to the next invocation of the function.
It seems to me zsh should reset the variable to a plain scalar
before assigning to the file names as input to the function.
--
Stephane
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-06-16 21:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-16 21:51 REPLY retains its integer attribute in glob qualifier functions Stephane Chazelas
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).