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.
How to debug ash/bash shell scripts
How to do things, solutions, recipes, tutorials
Message
Author
Return to “HOWTO ( Solutions )”
Jump to
- House Training
- ↳ Beginners Help ( Start Here)
- ↳ Users ( For the regulars )
- ↳ Für deutschsprachige Anhänger
- ↳ Pour les francophones
- ↳ Usuarios de habla Hispana
- ↳ HOWTO ( Solutions )
- ↳ Bugs ( Submit bugs )
- Advanced Topics
- ↳ Additional Software (PETs, n' stuff)
- ↳ Package Collections / Repositories
- ↳ REQUESTS
- ↳ Browsers and Internet
- ↳ Business
- ↳ Compiling
- ↳ Desktop
- ↳ Documents
- ↳ Drivers
- ↳ Educational
- ↳ Engineering/Science/Simulation
- ↳ Eye Candy
- ↳ Filesystem
- ↳ Games
- ↳ Graphics
- ↳ Multimedia
- ↳ Network
- ↳ Security/Privacy
- ↳ System
- ↳ Utilities
- ↳ Virtualization
- ↳ Unsorted
- ↳ Cutting edge
- ↳ Multi-session live-CD/DVD
- ↳ Hardware
- ↳ Audio
- ↳ Networking
- ↳ Dialup
- ↳ Ethernet
- ↳ Wireless
- ↳ Printers
- ↳ Video
- ↳ Puppy Derivatives
- ↳ Puppy Projects
- ↳ Next Puppy Development
- ↳ 4.x
- ↳ Bugs (4.x dev)
- ↳ Usability Issues (4.x dev)
- ↳ 5.x
- ↳ Bugs (5.x dev)
- ↳ Usability Issues (5.x dev)
- ↳ Localization Project
- ↳ Documentation Project
- Taking the Puppy out for a walk
- ↳ Announcements
- ↳ Puppy Power
- ↳ Suggestions
- ↳ Misc
- Off-Topic Area
- ↳ Programming
- ↳ Security
- ↳ Truly off-topic conversations
- ↳ Spam reports