kethd
Joined: 20 Oct 2005 Posts: 451 Location: Boston MA USA
Posted: Thu 22 Dec 2005, 16:07 Post subject:
How to debug ash/bash shell scripts
How to debug ash/bash shell scripts
Add echo statements in various places to show what is happening where. $LINENO is available in bash. Use set and env to dump the values of all the variables. In bash, <trap DEBUG> allows added code to be run after each statement.
Two flags are available, -v verbose and -x xtrace. They can be invoked with the start of the script:
# sh -vx scriptfile
or within the script:
set -vx
and can then be turned off within the script:
set +vx
The output can be copied to a logfile:
# sh -vx scriptfile 2>&1 | tee logfile
or redirected from within the script:
exec 1>logfile 2>&1
But that exec statement takes away all the screen output, leaving you running blind. For advanced tips, see:
http://www.murga.org/%7Epuppy/viewtopic.php?t=4802
capture screen output in a file
There is rumored to be a bash debugger for the latest version, but no news yet of any sightings within the known pupverse.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum