From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28386 invoked by alias); 5 Apr 2018 02:38:12 -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: 23309 Received: (qmail 26402 invoked by uid 1010); 5 Apr 2018 02:38:12 -0000 X-Qmail-Scanner-Diagnostics: from mta03.eastlink.ca 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(24.224.136.9):SA:0(-2.6/5.0):. Processed in 13.776363 secs); 05 Apr 2018 02:38:12 -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=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW, SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: rayandrews@eastlink.ca X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | MIME-version: 1.0 Content-transfer-encoding: 8BIT Content-type: text/plain; charset=utf-8; format=flowed X-Authority-Analysis: v=2.3 cv=dfKuI0fe c=1 sm=1 tr=0 a=RnRVsdTsRxS/hkU0yKjOWA==:117 a=RnRVsdTsRxS/hkU0yKjOWA==:17 a=IkcTkHD0fZMA:10 a=gir0-LH0AAAA:8 a=0mL-AJmJmcy4FKtcpqEA:9 a=M56NATXirCP6Xk9I:21 a=CfASgbpWsaHcVP-Q:21 a=QEXdDO2ut3YA:10 a=aLewGyoHDmJ4ULJHWpSz:22 X-EL-IP-NOAUTH: 24.207.101.9 Subject: Re: counting trouble To: zsh-users@zsh.org References: <469d8a16-69c9-79f2-bdce-467886913158@eastlink.ca> From: Ray Andrews Message-id: <83ca0dfb-b91f-31d8-5346-c2794f7d8658@eastlink.ca> Date: Wed, 4 Apr 2018 19:07:53 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 In-reply-to: Content-language: en-CA On 04/04/18 06:15 PM, Bart Schaefer wrote: > On Wed, Apr 4, 2018 at 11:21 AM, Ray Andrews wrote: >> >> 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? I'll take another look, that's a good clue anyway. > >> 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, Exactly the point of it.   I found I had to handle an exact match specially.  I'm sure there's a better way. > 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)? Yeah, but as I said, I've figured out that that won't happen, it's not a glob 'inside'.  So how would I get the results of the glob 'inside' as well as the single match not counting characters? .... but you've just said that shouldn't be happening, so I'll follow that clue. > 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. > But:    tmp=( ${1}*(N) ) ... seems to give me exactly that -- an array split on lines with no worries about spaces in filenames.  And '$#' counts the number of files just as I want.   print -l "${tmp[@]}\n" ... does exactly what I'm expecting (bottom example): 15 /aWorking/Zsh/Source/Wk 3 $ . try; find_match try,12 Exact match found: "try,12" 15 /aWorking/Zsh/Source/Wk 3 $ . try; find_match try,1 Unique match found: "try,1" 15 /aWorking/Zsh/Source/Wk 3 $ . try; find_match try,14 Exact match found: "try,14,interim" 15 /aWorking/Zsh/Source/Wk 3 $ . try; find_match try,* ERROR: No wildcards please 15 /aWorking/Zsh/Source/Wk 3 $ . try; find_match try, ERROR: 18:: 15 matches for "try,", please disambiguate or copy manually: try,1 try,10,working try,11,very nice, help text try,12 try,13 try,14,interim try,15,important noglob and messages try,2,exact match handled try,3,now add declare try,4,no ls try,5,shakeout bugs try,6,interim safe try,7,now with find_match try,8 try,9,working =========================================== What would be manna from heaven is to be able to look at an array and 'see' the construction of it -- how it's split, if one could see the newlines and/or spaces in both input and output that would be huge.  Even after several years I still find myself throwing syntax at things hopefully but almost randomly until eventually something works.  If I could see the hidden structure of both input and output there'd be a lot less guessing.