2 # I, Ian Kelling, follow the GNU license recommendations at
3 # https://www.gnu.org/licenses/license-recommendations.en.html. They
4 # recommend that small programs, < 300 lines, be licensed under the
5 # Apache License 2.0. This file contains or is part of one or more small
6 # programs. If a small program grows beyond 300 lines, I plan to switch
9 # Copyright 2024 Ian Kelling
11 # Licensed under the Apache License, Version 2.0 (the "License");
12 # you may not use this file except in compliance with the License.
13 # You may obtain a copy of the License at
15 # http://www.apache.org/licenses/LICENSE-2.0
17 # Unless required by applicable law or agreed to in writing, software
18 # distributed under the License is distributed on an "AS IS" BASIS,
19 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 # See the License for the specific language governing permissions and
21 # limitations under the License.
25 local help="Usage: isdiff [--help|-h] [-v] [-x] FILE1 FILE2
26 Test if FILE1 and FILE2 have the same contents
28 Returns 0 for same, 1 for diff, 2 for error.
31 -r use most reliable checksum available, ie. sha instead of md5"
35 if [[ $1 == --help ]] ||
[[ $1 == -[^
-]* && $1 == *h
* ]]; then
38 elif [[ $1 == -[^
-]* && $1 == *v
* ]]; then
41 elif [[ $1 == -[^
-]* && $1 == *r
* ]]; then
49 x
=($
(type -p sha512sum
) $
(type -p sha256sum
) $
(type -p sha1sum) $
(type -p md5sum))
50 if [[ $reliable ]]; then
53 sumbinary
=${x[${#x[@]}-1]}
57 echo "Need 1 of sha512sum sha256sum sha1sum or md5sum for sum() function"
60 if [[ $# != 2 ]]; then
61 [[ $v ]] && echo Error
: need
2 arguments.
65 x
=$
($sumbinary < "$1" ) ||
return 2
66 y
=$
($sumbinary < "$2" ) ||
return 2
68 { x
=$
($sumbinary < "$1" ) ;} 2>/dev
/null ||
return 2
69 { y
=$
($sumbinary < "$2" ) ;} 2>/dev
/null ||
return 2
71 if [[ $x == "$y" ]]; then
74 [[ $v ]] && echo "$1" "$2" different.