source: lab/trunk/TipAndDoc/.bin/cmpdir @ 170

Last change on this file since 170 was 170, checked in by mitty, 12 years ago
  • about #55
  • find -> sort -> uniq -> xargs -> cmp
  • don't check existence of path
  • don't check path is regular file or directory
  • Property svn:executable set to *
File size: 810 bytes
Line 
1#! /bin/sh
2
3if [ $# -lt 2 ]; then
4    echo "Usage: $0 directory1 directory2"
5    exit 1
6fi
7if [ -d "$1" -a -d "$2" ]; then
8    echo "$0: start comparing '$1' and '$2'" >&2
9fi
10
11list=`mktemp --tmpdir cmpdir.list.XXXXXXXXXX` || exit 1
12tmp=`mktemp --tmpdir cmpdir.tmp.XXXXXXXXXX` || exit 1
13trap "rm -- '$list' '$tmp'" EXIT
14
15wc=$PWD
16cd "$1"
17find ./ -print0 >> "$tmp"
18cd $wc
19
20cd "$2"
21find ./ -print0 >> "$tmp"
22cd $wc
23
24sort -z "$tmp" | uniq -z > "$list"
25
26comppath () {
27    [ ! -e "$1/$3" ] && [ ! -e "$2/$3" ] &&
28        (echo "$0: something wrong abount '$3'" >&2; return)
29    [ -e "$1/$3" ] && [ ! -e "$2/$3" ] &&
30        (echo "Only in '$1': '$3'" >&2; return)
31    [ ! -e "$1/$3" ] && [ -e "$2/$3" ] &&
32        (echo "Only in '$2': '$3'" >&2; return)
33}
34
35xargs -a "$list" -0 -n 1 -I entry cmp "$1/entry" "$2/entry"
Note: See TracBrowser for help on using the repository browser.