-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhexsum.sh
executable file
·55 lines (46 loc) · 954 Bytes
/
hexsum.sh
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
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
PATH=$HOME/bin
function usage()
{
echo ""
echo "hexdiff: by default, add second provided hex parameter to first."
echo "If the first argument is '-', subtract instead."
echo "Please supply two arguments that begin with '0x'."
echo ""
exit 1
}
if ( [[ $# -ne 2 ]] && [[ $# -ne 3 ]] ) ; then
usage
exit 1
fi
if [[ $# -eq 3 ]] ; then
if [[ ! $1 =~ "-" ]] ; then
usage
exit 1
else
first=`$HOME/bin/hex2dec $2`
if [ $? -gt 0 ] ; then
usage
exit 1
fi
second=`$HOME/bin/hex2dec $3`
if [ $? -gt 0 ] ; then
usage
exit 1
fi
result=$(($first - $second))
fi
else
first=`$HOME/bin/hex2dec $1`
if [ $? -gt 0 ] ; then
usage
exit 1
fi
second=`$HOME/bin/hex2dec $2`
if [ $? -gt 0 ] ; then
usage
exit 1
fi
result=$(($first + $second))
fi
echo `$HOME/bin/dec2hex $result`