Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
REPLY retains its integer attribute in glob qualifier functions
- X-seq: zsh-workers 43032
- From: Stephane Chazelas <stephane.chazelas@xxxxxxxxx>
- To: Zsh hackers list <zsh-workers@xxxxxxx>
- Subject: REPLY retains its integer attribute in glob qualifier functions
- Date: Sat, 16 Jun 2018 22:51:58 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:subject:message-id:mail-followup-to:mime-version :content-disposition:user-agent; bh=Gf2jc+02xlN7d150pwOcsRg//UBtpT7G/PzJyrAfICI=; b=Dr9OcQheRer7pmPRdv/1jECKhSaf7HYq1uTs7RDA4XTGToPN7BvisOhaCS+cHKjWV5 VaZ7wN+UH6G3ppJiXbbEsJe+pJ1WTXQAMu+zepPtSHM7JRaAuZ4gP0D7Pa2ucWyfiVpZ 9LYnfxbOryNKXU49rlq+Tfr7MDrnnuMzDJEWbDKY1E7Tnhwrx+pGNAAQZ/vxbkGk3g3s +y9AqUP1TJhfDj39+/mqf4vciTpnj2yVG58FdJ2VVaS4M7INSEgrlaOxYYBpC6QIrcZ4 Qk/FDdBVcrwgef/frRo6ypPA7bla1dhCipUSIlO0dUbGvyjAdLf7qobTA2qJxOzrElrf CAWw==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mail-followup-to: Zsh hackers list <zsh-workers@xxxxxxx>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author