-
Notifications
You must be signed in to change notification settings - Fork 0
/
assert.sh
executable file
·29 lines (25 loc) · 898 Bytes
/
assert.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
#!/bin/bash
# assert.sh
# http://tldp.org/LDP/abs/html/debugging.html#ASSERT
#######################################################################
assert () # If condition false,
{ #+ exit from script
#+ with appropriate error message.
E_PARAM_ERR=98
E_ASSERT_FAILED=99
if [ -z "$2" ] # Not enough parameters passed
then #+ to assert() function.
return $E_PARAM_ERR # No damage done.
fi
lineno=$2
if [ ! $1 ]
then
echo "Assertion failed: \"$1\""
echo "File \"$0\", line $lineno" # Give name of file and line number.
exit $E_ASSERT_FAILED
# else
# return
# and continue executing the script.
fi
} # Insert a similar assert() function into a script you need to debug.
#######################################################################