File: cmp_size

package info (click to toggle)
libzstd 1.5.7%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,348 kB
  • sloc: ansic: 89,030; sh: 3,788; python: 3,466; cpp: 2,927; makefile: 2,329; asm: 390
file content (44 lines) | stat: -rwxr-xr-x 705 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh

set -e

usage()
{
	printf "USAGE:\n\t$0 [-eq|-ne|-lt|-le|-gt|-ge] FILE1 FILE2\n"
}

help()
{
	printf "Small utility to compare file sizes without printing them with set -x.\n\n"
	usage
}

case "$1" in
	-h) help; exit 0  ;;
	--help) help; exit 0 ;;
esac

if ! test -f $2; then
	printf "FILE1='%b' is not a file\n\n" "$2"
	usage
	exit 1
fi

if ! test -f $3; then
	printf "FILE2='%b' is not a file\n\n" "$3"
	usage
	exit 1
fi


size1=$(wc -c < $2)
size2=$(wc -c < $3)

case "$1" in
	-eq) [ "$size1" -eq "$size2" ] ;;
	-ne) [ "$size1" -ne "$size2" ] ;;
	-lt) [ "$size1" -lt "$size2" ] ;;
	-le) [ "$size1" -le "$size2" ] ;;
	-gt) [ "$size1" -gt "$size2" ] ;;
	-ge) [ "$size1" -ge "$size2" ] ;;
esac