From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21419 invoked by alias); 5 Apr 2018 01:15:47 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: X-Seq: 23307 Received: (qmail 10214 invoked by uid 1010); 5 Apr 2018 01:15:47 -0000 X-Qmail-Scanner-Diagnostics: from mail-wm0-f53.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(74.125.82.53):SA:0(-1.9/5.0):. Processed in 2.005805 secs); 05 Apr 2018 01:15:47 -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,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=iupmr51W1meN7lye9EcK+Xc+s6f6HZ/MzyRuN8t4sVw=; b=YotYF8o3Sv8Ll6affwxvPscmbNYnjD5KVKnpHwT5UySJ6kiUQl+rcn9HlxRqa1iF+l 6rQPs2X8QvUtFgTZ5ppqvpAzdHCmUpL55JVyKOfyM2T10SC/2kPESq3ci73v7XF9Xxlb tqKL85W1mbTFADMCd73ilk/G8EK2F6Do8s0FRRQz0tahT4/UQyy3/o9F5RidJvp0TvNY zwFLyXGhGVRN9qDAgQMr9pJMXsd3nuVA4UwEub1L5NfjKjmuiPg8aJCeWTA5Hlmsv+aL 7efHJyFsmA/ZzGBArqREB/VMnoaFEgaWfkWRYjLvIQG59aI9vMZJdydkss9KC/HzZvF6 HlSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=iupmr51W1meN7lye9EcK+Xc+s6f6HZ/MzyRuN8t4sVw=; b=TlU1Aguohtsp6lZypi4cwTnssq/kNuMbJIsJNV8QyszZyhmSDI00EYv0sDj0je0kV2 AQoIOaVMPLsxptrpZV1tlOfY8Fzz5B2zTdiWWtaME7n4B6+LKPl09Z4+zqQEnIEQZ2Sa 4PheXmV4cUBZI+Icd6GenvxMBpB7PlSKeCIeg72Dh+Tf5yIjItf5PkhSwRugynh9/3k6 QjVWwr9xb+2leCG9lrcJQP/C0RoOZb16Nv1V6jLtdpmdjfPAH82GLxdPqqNFD4321Gi0 wqE/+0u8etyMcALgwjxZyvrZ+QrD/EZqAbV/bUqJBrGY3TyzACF+gVs/mHSszE5h3XVP fvHw== X-Gm-Message-State: ALQs6tA8X0Fy0IVwLAMl8SeajgdpG3rqO3N8gsrjt8MOxgxrfBDO3Hrv PP2oUeT8gLtqSFZKMrzNgxJO1/YQEZLKWpub7oekuA== X-Google-Smtp-Source: AIpwx4+8JkROfEd17qBKLp0o61FLK+78Z05ZrVc5Pq2dLFs1ggBYhpz6Fny52nHCN1zLSHKQh5QaTzIy6ztXG1RdUMk= X-Received: by 10.46.91.21 with SMTP id p21mr13041425ljb.38.1522890941448; Wed, 04 Apr 2018 18:15:41 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <469d8a16-69c9-79f2-bdce-467886913158@eastlink.ca> References: <469d8a16-69c9-79f2-bdce-467886913158@eastlink.ca> From: Bart Schaefer Date: Wed, 4 Apr 2018 18:15:40 -0700 Message-ID: Subject: Re: counting trouble To: Ray Andrews Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" On Wed, Apr 4, 2018 at 11:21 AM, Ray Andrews wrote: > > tmp=( $1*(N) ) > > if [[ "$#tmp" > 1 ]]; then > > Alas, if there is only one match then the count becomes a count not of lines > but of characters which is a nasty gotcha. That can't be all there is to it. $#array only becomes a count of characters if the context forces the array into string form. Which admittedly can happen in some non-obvious ways, but what you've shown above is not one of those ways. What are you really doing? > Hacking away I find this works: > > [ -e "$1" ] && tmp=( "${(f)${1}}" ) || tmp=( ${1}*(N) ) Umm ... [ -e "$1" ] will only succeed for a single literal file name, not a pattern, and the (f) flag means to split on newlines, so unless you have a file with newlines embedded in the name (in which case this is entirely broken a different way) there's no reason for ${(f)...} there at all. And none of this has anything to do with how [[ $#tmp > 1 ]] would work after the assignment. > expected this to work: " ${(f)${1}*} " but it doesn't. Expected it to do what? Filename generation like ${1}* out in the open (so to speak)? What led you to expect that? In any case filename generation would never produce a newline-separated string (again barring files with newlines in the name), so (f) would not do anything to the result. Please don't think about globbing as returning "lines". It doesn't.