How can debug our UNIX shell script?

Hi all,

i have two simple questions here...

  1. i want to know that how to debug the UNIX shell script?
  2. is there any way to handling the exception in UNIX shell script like oracle exception handling?

Please provide me those details it would be great help/

Thanks and Regards,
MPS
Bangalore

Hi,
Just a quick reply/hint as im not a shell expert :), add "set -x" in the begining of the script, this will display all commands that are about to be executed, hopefully helping you to know where your shell might bug ...
For 'handling exceptions' you can only catch signal like segfault, sigint (user hitting break key, etc ...) with the "trap" keyword ...

Good luck hunting bugs :smiley:

Hi,
on the overview,if your a naive user ,then the easiest way is to use

bash -xv <your script>

Assuming your using bash as your shell....
This will print the output line by line and will also include every statement with the corresponding actions,attributes and parameters you've passed!!!
It will list out each arg as and when they are called in the script ,so that it will be easier to debug...

Regards

PS:if your script is lengthy,be ready to scroll pages at a time, helpful nevertheless :wink:

u can debug unix scripts using ksh -vx <filename> , using echo statements and creating log files

1 Like