[NTLUG:Discuss] KSH scripting challenge

Leroy Tennison leroy_tennison at prodigy.net
Wed Sep 23 06:00:53 CDT 2009


Leroy Tennison wrote:
> I want to include some comments in the output of a script but compliance 
> also wants the commands contained in the script to be output along with 
> their result.  The -x switch will accomplish the latter but creates a 
> problem with the former.
> 
> If I use the echo command in a script (call it demo) as follows:
> 
> 	ksh -x demo
> 
> I get
> 
> 	+ echo 'Step 1'
> 	Step 1
> 
> If I echo redirect output to /dev/null using the same execution above I get:
> 
> 	+ echo 'Step 1'
> 	+ 1> /dev/null
> 
> which is better but I still have to live with the unwanted "echo" and "+ 
> 1> /dev/null" (bash doesn't list the annoying "+ 1> /dev/null" but it's 
> not an option).
> 
> The -x option doesn't output comments (at least not ones beginning with 
> a #).
> 
> An example of what I really want the output to look like is -
> 
> 	Step 1
> 	+ grep -v ^# inittab | grep initde
> 	id:5:initdefault:
> 	+ grep ca: inittab
> 	ca::ctrlaltdel:/sbin/shutdown -r -t 4 now
> 
> and so on.
> 
> Any ideas or better suggestions?
> 
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss
> 

Thought I'd mention the "final resolution" for any one else's benefit 
since it was a little different that what was said so far.  Ran across 
the -v switch which along with the colon command, met my needs perfectly.

The -v switch prints exactly what's in the script (including comments) 
and honors spacing (leading tabs in front of commands, etc.)

The -x switch looks to be more for debugging, showing how the 
interpreter processed pipelines, redirection, etc.



More information about the Discuss mailing list