From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 991bac14 for ; Mon, 8 Apr 2019 14:38:47 +0000 (UTC) Received: (qmail 19430 invoked by alias); 8 Apr 2019 14:38:30 -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: 23906 Received: (qmail 650 invoked by uid 1010); 8 Apr 2019 14:38:29 -0000 X-Qmail-Scanner-Diagnostics: from reka.pair.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.101.1/25412. spamassassin: 3.4.2. Clear:RC:0(209.68.5.132):SA:0(-1.9/5.0):. Processed in 3.355747 secs); 08 Apr 2019 14:38:29 -0000 X-Envelope-From: nkuitse@nkuitse.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at nkuitse.com does not designate permitted sender hosts) Date: Mon, 8 Apr 2019 10:37:48 -0400 From: Paul Hoffman To: zsh-users@zsh.org Subject: Re: find duplicate files Message-ID: <20190408143748.GA21630@trot> Mail-Followup-To: zsh-users@zsh.org References: <86v9zrbsic.fsf@zoho.eu> <20190406130242.GA29292@trot> <86tvfb9ore.fsf@zoho.eu> <86mul2apj8.fsf@zoho.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <86mul2apj8.fsf@zoho.eu> User-Agent: Mutt/1.5.23 (2014-03-12) On Sat, Apr 06, 2019 at 09:42:51PM +0200, Emanuel Berg wrote: > zv wrote: > > >> Cool, but doesn't seem to work? > >> > > > > Forgot to ignore the second field. Oops, my bad! > > #!/bin/zsh > > find-duplicates () { > > (( # > 0 )) || set -- *(.N) > > local dups=0 > > md5sum $@ | sort | awk '{ print $2,$1 }' | uniq -c -f1 | \ > > grep -v '^ *1 ' | wc -l | read dups > > (( dups == 0 )) && echo "no duplicates" > > } > > Still nothing :) What were you expecting? It exits with status 0 if there were no duplicates; otherwise, it exits with status 1. > What's with the third line BTW? Looks like > a comment to me and my editor interprets it that > way as well. > > But changing it to $# doesn't help :( This might make it clearer: (( n == 0 )) || echo "n = $n, expected 0" (( # == 0 )) || echo "# = $#, expected 0" # is the name of a variable (a "variable" is zsh terminology). Its value is the number of positional parameters, i.e., the number of elements in $argv. Within (( ... )) you don't need the dollar sign before a variable name, but (for the most part) it doesn't hurt to use it, and so you can write (( # > 0 )) or (( $# > 0 )) or (( #argv > 0 )) or (( $#argv > 0 )) all with the same effect. Paul. -- Paul Hoffman