We can implement an intelligent DEBUG-function to debug a script at specified line by putting the following function at the beginning of the script:
_DEBUG="on"
function DEBUG()
{
[ "$_DEBUG" == "on" ] && $@
}
When done with debugging or before moving your script to production, set "_DEBUG" to 'off'.
_DEBUG="off" # set to anything but not to 'on'
For Example:
#!/bin/bash
_DEBUG="on"
function DEBUG()
{
[ "$_DEBUG" == "on" ] && $@
}
DEBUG echo 'Hi!'
_DEBUG="on"
function DEBUG()
{
[ "$_DEBUG" == "on" ] && $@
}
When done with debugging or before moving your script to production, set "_DEBUG" to 'off'.
_DEBUG="off" # set to anything but not to 'on'
For Example:
#!/bin/bash
_DEBUG="on"
function DEBUG()
{
[ "$_DEBUG" == "on" ] && $@
}
DEBUG echo 'Hi!'
No comments :
Post a Comment