SUMMARY: Solaris 2.6 ksh: prog1 | prog2 | while...

From: Sam Nelson (
Date: Fri Oct 23 1998 - 05:35:56 CDT

The original query concerned a shell script from inside HP's `JetAdmin for
Solaris' utilities, containing a loop of the form

cat file | awk | sort | while LINE=`line`;
    some stuff with $LINE

I had about ten responses, the majority of which castigated me for writing
bad code. It wasn't my code, it was HP's!

Anyway, several different solutions were suggested, most of which involved
replacing `while LINE=`line`' with

  while read LINE # neat, but different semantics---but works in this case!


  while read -r LINE # neater, but still some semantic troubles

or even replacing the whole loop with something like

while LINE=$(line); do
  mess with $LINE
done <<EOF
 generate some lines

which looks weird but works well. Several respondents pointed out that

  $ cat file | awk

is the same as

  $ awk file

(mostly), for which again Mr Hewlett and Mr Packard and their minions can take
credit (and a Korn shell programming course, I reckon!).

A couple of respondents suggested that Sun's shells have over many years
suffered on the semantic front from over-enthusiastic attempts at optimisation,
and one pointed me at for copies
of shiny new ksh93 and other tools for Solaris. I've grabbed these but I
haven't tested them yet, but this particular respondent is a) known well to me,
b) reliable and c) says he hasn't looked back. Clearly there are better things
to write scripts in than plain old boring shell, these days.

All I have left now, having set up lots of lovely reliable printers (including
discovering that HP drive Lexmark printers from Solaris better than Lexmark do)
is to figure out where to report the bug!

Thanks everyone,


Sam Nelson, Comp Sci, Stirling U, FK9 4LA, Scotland         ,->0->M
Email:    Phone: +44 7050 165499     I->3-+->2->R=->-+->4->O
Office: +44 1786 467443      Fax: +44 1786 464551           `->1->S=->-'
URL:  NS80799622/38m   R$+@$+  $@smtp$#$2$:$1@$2

This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:12:51 CDT