source: lab.git/TipAndDoc/.bin/cmpdir @ aa2cedc

trunk
Last change on this file since aa2cedc was 1be8507, checked in by mitty <mitty@…>, 12 years ago
  • #55
  • fix: when dir1/target and dir2/target both exist but file type differ, only output dir1 and dir2 (drop ./target information)

git-svn-id: https://lab.mitty.jp/svn/lab/trunk@172 7d2118f6-f56c-43e7-95a2-4bb3031d96e7

  • Property mode set to 100755
File size: 1.1 KB
Line 
1#! /bin/sh
2
3if [ $# -lt 2 ]; then
4    echo "Usage: $0 directory1 directory2"
5    exit 1
6fi
7if [ $# -eq 3 ]; then
8    [ -d "$1/$3" ] && [ -d "$2/$3" ] &&
9        exit
10    [ ! -e "$1/$3" ] && [ ! -e "$2/$3" ] &&
11        echo "$0: something wrong abount '$3'" >&2 && exit
12    [ -e "$1/$3" ] && [ ! -e "$2/$3" ] &&
13        echo "Only in '$1': '$3'" >&2 && exit
14    [ ! -e "$1/$3" ] && [ -e "$2/$3" ] &&
15        echo "Only in '$2': '$3'" >&2 && exit
16    [ -f "$1/$3" ] && [ -d "$2/$3" ] &&
17        echo "'$1/$3' is a regular file but '$2/$3' is a directory" >&2 && exit
18    [ -d "$1/$3" ] && [ -f "$2/$3" ] &&
19        echo "'$1/$3' is a directory but '$2/$3' is a regular file" >&2 && exit
20   
21    cmp -s "$1/$3" "$2/$3" || echo "$1/$3" "$2/$3" are differ >&2
22    exit
23fi
24if [ -d "$1" -a -d "$2" ]; then
25    echo "$0: start comparing '$1' and '$2'" >&2
26fi
27
28list=`mktemp --tmpdir cmpdir.list.XXXXXXXXXX` || exit 1
29tmp=`mktemp --tmpdir cmpdir.tmp.XXXXXXXXXX` || exit 1
30trap "rm -- '$list' '$tmp'" EXIT
31
32wc=$PWD
33cd "$1"
34find -print0 >> "$tmp"
35cd $wc
36
37cd "$2"
38find -print0 >> "$tmp"
39cd $wc
40
41sort -z "$tmp" | uniq -z > "$list"
42
43
44xargs -a "$list" -0 -n 1 -I entry $0 "$1" "$2" "entry"
Note: See TracBrowser for help on using the repository browser.