[NTLUG:Discuss] KSH scripting challenge
Fred James
fredjame at fredjame.cnc.net
Thu Sep 17 08:45:55 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?
>
>
Leroy Tennison
Sorry - not sure how you might get the '#' comment lines (at least not
interlaced), but I believe the rest could be done by using a unique
string in certain echo statements, and then grep -v them out of the
output - haven't tried this, of course - hope this helps
Oh, is my assumption correct that the output is to be to screen, not file?
Regards
Fred James
More information about the Discuss
mailing list