| 1 | #!/bin/sh |
| 2 | |
| 3 | set -e |
| 4 | |
| 5 | usage() |
| 6 | { |
| 7 | printf "USAGE:\n\t$0 [-eq|-ne|-lt|-le|-gt|-ge] FILE1 FILE2\n" |
| 8 | } |
| 9 | |
| 10 | help() |
| 11 | { |
| 12 | printf "Small utility to compare file sizes without printing them with set -x.\n\n" |
| 13 | usage |
| 14 | } |
| 15 | |
| 16 | case "$1" in |
| 17 | -h) help; exit 0 ;; |
| 18 | --help) help; exit 0 ;; |
| 19 | esac |
| 20 | |
| 21 | if ! test -f $2; then |
| 22 | printf "FILE1='%b' is not a file\n\n" "$2" |
| 23 | usage |
| 24 | exit 1 |
| 25 | fi |
| 26 | |
| 27 | if ! test -f $3; then |
| 28 | printf "FILE2='%b' is not a file\n\n" "$3" |
| 29 | usage |
| 30 | exit 1 |
| 31 | fi |
| 32 | |
| 33 | |
| 34 | size1=$(wc -c < $2) |
| 35 | size2=$(wc -c < $3) |
| 36 | |
| 37 | case "$1" in |
| 38 | -eq) [ "$size1" -eq "$size2" ] ;; |
| 39 | -ne) [ "$size1" -ne "$size2" ] ;; |
| 40 | -lt) [ "$size1" -lt "$size2" ] ;; |
| 41 | -le) [ "$size1" -le "$size2" ] ;; |
| 42 | -gt) [ "$size1" -gt "$size2" ] ;; |
| 43 | -ge) [ "$size1" -ge "$size2" ] ;; |
| 44 | esac |