[NTLUG:Discuss] KSH scripting challenge

Leroy Tennison leroy_tennison at prodigy.net
Fri Sep 18 00:12:56 CDT 2009


Rusty Haddock wrote:
> Leroy Tennison wrote:
>     >...
>     >The -x option doesn't output comments (at least not ones beginning with 
>     >a #).
> 
> Are there any other ways to comment in 'ksh'?  :-)
> 
>     >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.
> 
> How 'bout using 'set -x' inside your script and just calling it
> with "ksh demo"???
> 
> 	echo "Step 1"
> 	set -x
> 	grep -v ^# inittab | grep initde
> 	grep ca: inittab
> 	set +x ; echo "Step Too" ; set -x
> 	grep ^rusty /etc/passwd
> 
> Oh, and to replace those leading '+'s, try using something like:
> 
> 	PS4="# "
> 
> My version of 'ksh' is "Version JM 93t+ 2008-12-10" from Fedora 10 so
> your mileage may vary. Using the above script I get the output of:
> 
> 	[1136] -=> ksh foo
> 	Step One
> 	# grep -v ^# inittab
> 	# grep initde
> 	id:5:initdefault:
> 	# grep :ca inittab
> 	Step Too
> 	# grep ^rusty /etc/passwd
> 	rusty:x:500:500:Rusty Haddock:/home/rusty:/bin/ksh
> 
> This version of 'ksh' splits pipelined commands.
> 
> Maybe this has helped.  My $0.02.... FWIW nowadays. :-)
> 
> 	-Rusty-
> 
> P.S.  Yes, I know how to spell 'two'.

Two good points, thanks.  I'd seen 'set x' but hadn't connected it with 
the idea of selective use.  I also hadn't realized that PS4 affected KSH 
output, will have to look into that.



More information about the Discuss mailing list