Debugging shell scripts
Updated January 21, 2003
Created January 21, 2003


Autogenerated Site Map
Search this Site!:
Search this site powered by FreeFind

Here are some notes on doing some bash debugging:

For the simple script you can call it with the -x option as follows:

sh -x myscript.sh

If your script is complex (and calls multiple other scripts) then maybe this is appropriate:

alias sh='sh -x'
alias bash='bash -x'
alias /bin/sh='/bin/sh -x'
alias /bin/bash='/bin/bash -x'

./myscript.sh

Or if you really need control, and your subscript recreates its own shell environment
and won't listen to you, then whack it over the head with the following (use at your own risk,
be sure to put everything back where you got it from):

cp -a /bin/sh /bin/sh.real
cat <<EOF>/bin/sh
#!/bin/bash -x
/bin/sh.real $@
EOF
./myscript.sh

Then whenever the script calls /bin/sh (or just sh) it will be forced to have the
debugging turned on.

Search this Site!:
Search this site powered by FreeFind

Homepage: http://www.cpqlinux.com
Site Map: http://www.cpqlinux.com/sitemap.html