Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: find duplicate files



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 <nkuitse@xxxxxxxxxxx>



Messages sorted by: Reverse Date, Date, Thread, Author