help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Comparing arrays


From: Chris Down
Subject: Re: [Help-bash] Comparing arrays
Date: Mon, 1 Apr 2013 10:41:08 +0800
User-agent: Mutt/1.5.21 (2010-09-15)

On 2013-04-01 10:21, Chris Down wrote:
> snip

Slightly faster method so that we don't iterate after we know the position of
the pivot:

    deleteOld() {
        local newFile oldFile found
        local oldFiles=()
        local newFiles=()

        while (( $# )); do
            if [[ "$1" == "" ]]; then
                newFiles=( "${@:2}" )
                break
            fi
            oldFiles+=( "$1" )
            shift
        done

        for oldFile in "address@hidden"; do
            found=0
            for newFile in "address@hidden"; do
                if [[ "$oldFile" == "$newFile" ]]; then
                    found=1
                    break
                fi
            done
            (( found )) || rm "$oldFile"
        done
    }


Also $arg, $newFile, $oldFile and $found should have been local in my first
posting.

Chris

Attachment: pgpY12Qqg38c8.pgp
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]