Operating System - HP-UX
1837371 Members
3465 Online
110116 Solutions
New Discussion

Need to see each commands in a Shell script while running

 
SOLVED
Go to solution
ezhilarasan_1
Occasional Advisor

Need to see each commands in a Shell script while running

Hi,

I want to see each commands in a Shell script while running. Normally while running a script, it will not display every commands built in the script. But I want to see. I hope, some set command will help ..but I forgot.

Thanks
R.Ezhil

5 REPLIES 5
A. Clay Stephenson
Acclaimed Contributor

Re: Need to see each commands in a Shell script while running

set -x
If it ain't broke, I can fix that.
Michael Steele_2
Honored Contributor
Solution

Re: Need to see each commands in a Shell script while running

#!/usr/bin/ksh
set -xv

Note: 'set -xv' will ignore commands embedded within functions. Just add another 'set -xv' to get around this. For example:

#!/usr/bin/ksh
set -xv

out_put ()
{
...
}
###############
Main

for i in $LIST
do
echo $i
done
###############

In this example on the for loop in Main will be displayed while the function 'out_put () ' will not.

To get around this :

out_put ()
{
set -xv
...
}
Support Fatherhood - Stop Family Law
Steve Bonds
Trusted Contributor

Re: Need to see each commands in a Shell script while running

Or, if you don't want to modify the script itself:

sh -xv <script name>

-- Steve
Dave La Mar
Honored Contributor

Re: Need to see each commands in a Shell script while running

To add to what the experts have already stated, I will commonly do
#!/usr/bin/ksh -x
rest of script

while testing.

Best of luck.

Regards,

dl
"I'm not dumb. I just have a command of thoroughly useless information."
John Meissner
Esteemed Contributor

Re: Need to see each commands in a Shell script while running

in your script you could also have it echo the commands you are going to run
All paths lead to destiny