From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29252 invoked by alias); 5 Apr 2018 00:01:40 -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: 23305 Received: (qmail 25444 invoked by uid 1010); 4 Apr 2018 18:51:26 -0000 X-Qmail-Scanner-Diagnostics: from mta01.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.30):SA:0(-2.6/5.0):. Processed in 2.769409 secs); 04 Apr 2018 18:51:26 -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=OKgJIxSB c=1 sm=1 tr=0 a=RnRVsdTsRxS/hkU0yKjOWA==:117 a=RnRVsdTsRxS/hkU0yKjOWA==:17 a=IkcTkHD0fZMA:10 a=8N6KCFsDVBVMaij7VQ4A:9 a=QEXdDO2ut3YA:10 X-EL-IP-NOAUTH: 24.207.101.9 To: Zsh Users From: Ray Andrews Subject: counting trouble Message-id: <469d8a16-69c9-79f2-bdce-467886913158@eastlink.ca> Date: Wed, 4 Apr 2018 11:21:17 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 Content-language: en-CA I have a function that attempts a unique filename match for the argument and warns you if what you have entered can't be disambiguated.  It's easy if there are multiple matcheswhich is of course 'unsuccessful' but at least gives an honest report of the ambiguity:     tmp=( $1*(N) )     if [[ "$#tmp" > 1 ]]; then         echo "count is: $#tmp"         print -rl " More than one match:\n ${tmp[@]}\n" fi Alas, if there is only one match then the count becomes a countnot of lines but of characterswhich is a nasty gotcha. Hacking away I find this works:     [ -e "$1" ] && tmp=( "${(f)${1}}" ) || tmp=( ${1}*(N) )     ... ... the first assignment forces the line count.  But that's surely monstrous.  I've tried a single assignment but nothing seems legal as far as getting the wildcard inside the '${(f) ...}' construction.  I'd have expected this to work: " ${(f)${1}*} " but it doesn't. Is something civilized possible?  I've sorta figured out that the wildcard is no longer a wildcard in there, but what to do?