I do agree ;) the latest version ksh93s has just been released and offers quite a lot of new goodies (regex extensions and lots of utf8 fixes). The extension mechanism that has been there since the beginnings of ksh93 in 93 ;) is quite. By the way as cat is a builtin of modern ksh (and the last command of the pipeline in ksh is executed by main()) the efficiency of 'cat...| cmd' is (usually) hardly a problem. From the command line, and I often use a cat like this, in case I need to edit later to put 'cat -evnt' o even to sandwich some extra "line" like this
{ echo; cat ...; echo; } | whatever
But... there is an exception actually 'cmd | while read' is probably one of "worst" constructs in terms of efficiency as the shell needs to read one byte at a time in case another command in the body of the while could compete for stdin. If it is *not* the case, a trick like this (for modern enough shells) is nice:
use 'cmd | while read -u9 ...; done 9<&0-' desc 0 is duped on desc 9 and then closed
# an example of healthy competition for stdin
while read header
do
dd ...
done
Note that you need a true move-close and not 9>&0 0<&- as by the time the dup is done, the close doesn't know about it and does not set a share flag. ksh88 does not have the logic needed for example. If your system pipes are dumb (no peek ahead) the trick does not work either.
I finish with some hack. the 'while < file' idiom
does that move-close magic under the hood (and does a 'set' on each line read) and is quite efficient. "under cover select" is what you get if you stack them 'while <file1 <file2 ...' ;)
% stephan@labaule (/home/stephan) %
% $0 --version; cat -n hi1
version sh (AT&T Labs Research) 1993-12-28 r
1 just
2 another
3 ksh
4 hacker
% stephan@labaule (/home/stephan) %
% while < hi1; do print -n $1' '; done; echo
just another ksh hacker
David Korn's own words on this (thread of ast-users mailing list on july 2006) are interesting from a un*x perspective: https://mailman.research.att.com/pipermail/ast-users/2006q3/001084.html
enjoy
--stephan
|