[NTLUG:Discuss] KSH scripting challenge

Leroy Tennison leroy_tennison at prodigy.net
Wed Sep 16 23:21:01 CDT 2009


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?



More information about the Discuss mailing list