[NTLUG:Discuss] KSH scripting challenge
Rusty Haddock
rusty at fe2o3.lonestar.org
Thu Sep 17 14:06:53 CDT 2009
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'.
--
_____ Rusty Haddock <=> AE5AE
|\/ o \ o Way out yonder in the
| ( -< O o Van Alstyne (TX) Metropolitan Area
|/\__V__/ Math illiteracy affects 7 out of 5 people!
More information about the Discuss
mailing list