From: mitty Date: Thu, 4 Oct 2012 09:05:56 +0000 (+0000) Subject: * about #55 X-Git-Url: http://lab.mitty.jp/git/?a=commitdiff_plain;h=5eea6d8cf8e3500fb1df24de687bbc0d622534cb;p=lab.git * about #55 * find -> sort -> uniq -> xargs -> cmp * don't check existence of path * don't check path is regular file or directory git-svn-id: https://lab.mitty.jp/svn/lab/trunk@170 7d2118f6-f56c-43e7-95a2-4bb3031d96e7 --- diff --git a/TipAndDoc/.bin/cmpdir b/TipAndDoc/.bin/cmpdir new file mode 100755 index 0000000..f8f546a --- /dev/null +++ b/TipAndDoc/.bin/cmpdir @@ -0,0 +1,35 @@ +#! /bin/sh + +if [ $# -lt 2 ]; then + echo "Usage: $0 directory1 directory2" + exit 1 +fi +if [ -d "$1" -a -d "$2" ]; then + echo "$0: start comparing '$1' and '$2'" >&2 +fi + +list=`mktemp --tmpdir cmpdir.list.XXXXXXXXXX` || exit 1 +tmp=`mktemp --tmpdir cmpdir.tmp.XXXXXXXXXX` || exit 1 +trap "rm -- '$list' '$tmp'" EXIT + +wc=$PWD +cd "$1" +find ./ -print0 >> "$tmp" +cd $wc + +cd "$2" +find ./ -print0 >> "$tmp" +cd $wc + +sort -z "$tmp" | uniq -z > "$list" + +comppath () { + [ ! -e "$1/$3" ] && [ ! -e "$2/$3" ] && + (echo "$0: something wrong abount '$3'" >&2; return) + [ -e "$1/$3" ] && [ ! -e "$2/$3" ] && + (echo "Only in '$1': '$3'" >&2; return) + [ ! -e "$1/$3" ] && [ -e "$2/$3" ] && + (echo "Only in '$2': '$3'" >&2; return) +} + +xargs -a "$list" -0 -n 1 -I entry cmp "$1/entry" "$2/entry"