1835927 Members
2882 Online
110088 Solutions
New Discussion

ksh problem

 
Ricky Tang
New Member

ksh problem

I wonder how to trace a ksh script line by line but without actually executing the commands.
9 REPLIES 9
Thierry Poels_1
Honored Contributor

Re: ksh problem

hi,
"ksh -n script" does a syntax check of your script without executing it; not perfect, but something to begin with ;)
regards,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Carsten Krege
Honored Contributor

Re: ksh problem

If you put a "set -x" at the beginning of a script, you will get a trace of the script to stdout. Of course the commands will still be executed. Here is an example:

#!/usr/bin/ksh
set -x

A="Hello World!"
echo $A


The output when executing the script is:

+ A=Hello World!
+ echo Hello World!
Hello World!


Carsten
-------------------------------------------------------------------------------------------------
In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move. -- HhGttG
Ricky Tang
New Member

Re: ksh problem

Hi Carsten,

The point is I do not want to
execute the script, just parsing it. Any idea?
Laurent Paumier
Trusted Contributor

Re: ksh problem

If you want to check your script for syntax errors, use the -n option (as stated by Thierry). If you just want to see the statements without executing them, use the 'cat' command ;)
Ricky Tang
New Member

Re: ksh problem

Maybe I should make my question more clearly.
What I want is something
like a debugger which can
show me the actual command
after filename and variable
expansions; but without
actually executing the
command


Printaporn_1
Esteemed Contributor

Re: ksh problem

I think we don't have that debug tool
enjoy any little thing in my life
Paula J Frazer-Campbell
Honored Contributor

Re: ksh problem

Hi Ricky

What you could do is create a temp dir with appropiate file in it and point your script at this area, this of course depends upon your script.

Paula
If you can spell SysAdmin then you is one - anon
Fred Martin_1
Valued Contributor

Re: ksh problem

No real way to do that, other than what's already been said. But one place I worked always did this with scripts (and, c programs for that matter):

At the head of the script, define the path to the data files:

datapth=/db/test
#datapth=/db/real

The path to the "live" data is commented-out.

All references in the script use the variable to point to the data.

So, while you write and debug your script you are using test data.

Then, to put the script into production, swap the comment tothe other path setting.

Fred
fmartin@applicatorssales.com
Jack Werner
Frequent Advisor

Re: ksh problem

You can create a function like
echodo ( echo "$*" }

You can assign a variable x = "echodo" and prefix every command with the $x variable. To turn it off just set x="" (null) and commands will run.
i'm retired