From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3285 invoked by alias); 16 Jun 2018 21:52:05 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 43032 Received: (qmail 16918 invoked by uid 1010); 16 Jun 2018 21:52:05 -0000 X-Qmail-Scanner-Diagnostics: from mail-wr0-f176.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.128.176):SA:0(-1.9/5.0):. Processed in 1.23119 secs); 16 Jun 2018 21:52:05 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: stephane.chazelas@gmail.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | 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== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :mime-version:content-disposition:user-agent; bh=Gf2jc+02xlN7d150pwOcsRg//UBtpT7G/PzJyrAfICI=; b=a2LpeMk365oJ7mo2o/c0nDowtMD6sBpqoOKuwpTDArzrUjgzqJkCRzPpuBEthuK+lC O90k0c2j4cxdFr5V5cXqM4AXNXXOVofrDsJbcOf55X+bSwF//kPDeDwa/HEcSEiVK0Dc adZX6leeWqVKRnOlBrZ21UiwmxxpWXg/B20CdAWW51YlQ0ydDWi5cRq8T/PSgzOGEYE+ XyU2pupWJECKP6mCkQoLe8sLITDkW6ALOMyIk/IKG9FbI4kWrn8LvbfH7r/viLf7Ttq5 rxGzHU5WOJXriV48v2xd94hkyp1t/SXZoX+4yXtqYJs6VeXHy0drHbejbksrnNuK21fy MnjQ== X-Gm-Message-State: APt69E23Kxp+8xq/4BcS2lAiSth2LyMUViFKuXnuoa9/ZnSPM6wTiSVL j4WwStrvDC70HfME1JlPxOmc1g== X-Google-Smtp-Source: ADUXVKJqVGROODfGqDeNgwWlvz9sAFShlYsghzfhyYUYIYPQ4GmwpUA+fvtAmjc1qQwEySW7xLTFtA== X-Received: by 2002:adf:c60d:: with SMTP id n13-v6mr5507174wrg.177.1529185920345; Sat, 16 Jun 2018 14:52:00 -0700 (PDT) Date: Sat, 16 Jun 2018 22:51:58 +0100 From: Stephane Chazelas To: Zsh hackers list Subject: REPLY retains its integer attribute in glob qualifier functions Message-ID: <20180616215158.GB10601@chaz.gmail.com> Mail-Followup-To: Zsh hackers list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) 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