From: Stephane Chazelas <stephane.chazelas@gmail.com>
To: Zsh hackers list <zsh-workers@zsh.org>
Subject: REPLY retains its integer attribute in glob qualifier functions
Date: Sat, 16 Jun 2018 22:51:58 +0100 [thread overview]
Message-ID: <20180616215158.GB10601@chaz.gmail.com> (raw)
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
reply other threads:[~2018-06-16 21:52 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180616215158.GB10601@chaz.gmail.com \
--to=stephane.chazelas@gmail.com \
--cc=zsh-workers@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).