source: lab.git/TipAndDoc/.bin/cmpdir @ 0dcad9a

trunk
Last change on this file since 0dcad9a 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
RevLine 
[5eea6d8]1#! /bin/sh
2
3if [ $# -lt 2 ]; then
4    echo "Usage: $0 directory1 directory2"
5    exit 1
6fi
[22a2ffd]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" ] &&
[1be8507]17        echo "'$1/$3' is a regular file but '$2/$3' is a directory" >&2 && exit
[22a2ffd]18    [ -d "$1/$3" ] && [ -f "$2/$3" ] &&
[1be8507]19        echo "'$1/$3' is a directory but '$2/$3' is a regular file" >&2 && exit
[22a2ffd]20   
21    cmp -s "$1/$3" "$2/$3" || echo "$1/$3" "$2/$3" are differ >&2
22    exit
23fi
[5eea6d8]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"
[22a2ffd]34find -print0 >> "$tmp"
[5eea6d8]35cd $wc
36
37cd "$2"
[22a2ffd]38find -print0 >> "$tmp"
[5eea6d8]39cd $wc
40
41sort -z "$tmp" | uniq -z > "$list"
42
43
[22a2ffd]44xargs -a "$list" -0 -n 1 -I entry $0 "$1" "$2" "entry"
Note: See TracBrowser for help on using the repository browser.