Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Any tools for debugging shell scripts? 1

Status
Not open for further replies.

ChrisCarroll

Programmer
Oct 10, 2000
177
I am tasked with debugging a process, written 6 years ago, which no longer works.
It is an executable called from a shell script with an environment set up by a shell script called from a function in a series of shell scripts that implement a batch processor : so it's a nest of scripts that I've spend 2 weeks working through and still haven't entirely worked out.

It would all be so much easiser if I had the normal tools of an application debugger : single step; source code view; breakpoints ; and so on.

For instance: I define a parameter file:

ParamFile=/usr/users/...

and then launch. But the process halts saying

ParamFile=/user/users/.... can't be found.

I have no idea how '/usr/users' got turned into '/user/users'. If only I could set a breakpoint.

But all I've got is #!/bin/sh -x

Is there anything better out there?

Chris
 
i know to debug a line at a time, I run my script like such:

ksh -k scriptname.ksh

___________________________________
[morse]--... ...--[/morse], Eric.
 
I don't think that -k causes scriptname.ksh to be executed one line at a time, allowing you to pause at each line and examine the environment though does it?

 
no, not one line at a time, but it gives you debug info for the entire script when it runs, what its doing, etc...., very detailed.

___________________________________
[morse]--... ...--[/morse], Eric.
 
The -a param to ksh will cause all variables to automatically be exported. If you're using ksh, or have a similar option for the shell you're using, you can then place an invocation of the shell as a breakpoint, and examine the inherited environment.



Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
Rod, Thanks the -a option is helpful.
So: I use
set -a
before launching the whole thing.

However the batch processor starts processes in a way that overrides it, so I only get a partial environment.

I get round that by replacing
#!/bin/sh
with
#!/bin/ksh -a

at the top of the scripts.

(Subquery : If I put
#!/bin/ksh -xa
or
#!/bin/ksh -a -x
it fails. I can have -x or -a but not both. Any ideas why?)

At the point I want a breakpoint, I insert :
ksh -i -a

Since the scripts I'm working with redirect output, I can then type but can't see anything.

I resolve this by typing
dtterm (I'm on DigitalUnix aka HP tru64) which opens up a new, properly working shell, in X; and allows me to inspect the environment.

which is what I wanted, even if a bit long winded.

Thanks,

Chris
 
(Subquery : If I put
#!/bin/ksh -xa
or
#!/bin/ksh -a -x
it fails. I can have -x or -a but not both. Any ideas why?)

No idea, and Korn's book says that shebang behaviour is system dependent. Testing on AIX, I can't even use one of them. The system independent workaround is to add these two lines to the top of the file:

set -o xtrace
set -o allexport

Rod Knowlton
IBM Certified Advanced Technical Expert pSeries and AIX 5L

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top