ksh93 problem

j. van den hoff veedeehjay at googlemail.com
Tue Nov 22 03:49:36 PST 2011


hi,

not so much a macports question, but probably a ksh93 bug (or so I do  
believe), which I don't know where to report:

short version:
==============
the `read' built-in is supposed to read a single input line (up to a  
linefeed). it does'nt work correctly with very long input lines but rather  
returns a truncated string of length 253952 without any notification  
(e.g., via return status).


long version:
=============
try this:

1. generate a file `longline.txt' containing some very long string,  e.g.  
with:

=====CUT=====
#!/bin/ksh

if (($# == 0)); then
    imax=262144
else
    imax=$1
fi

print "just a moment..."
for ((i=1;i<$imax;i++)); do buf="${buf}."; done
buf="${buf}+"

print $buf > longline.txt
=====CUT=====

which generates a file with a single line of 262143 repeated `.'  
characters plus a single `+' (and a \n).

at this point, `wc longline.txt' yields 262145 chars (due to trailing \n).

now, in `ksh' from the command line, do

read a < longline.txt
echo $?                   ### yields `0', i.e. "no error"
echo ${#a}                ### yields a string length of 253952
echo $a                   ### shows the truncation

253952 thus is the length of the returned truncated string for an actual  
line length >= 262144 (plus \n). to make it a bit more confusing,  
shortening the line by a single character to a length of 262143 (plus \n)  
leads to correct reading and

echo ${#a}   ###yields string length 2621413

now, 2621414-253952=8192, so it seems that the input buffer length is 8192  
bytes and if the line length does not exceed the sum of 253952 plus buffer  
length, the reading still works as expected.

I've seen this with Version JM 93t+ 2010-06-21 under MacOS as well as  
ubuntu. I find this behavior nowhere documented and presume it's a bug.

I would appreciate any feedback whether this behaviour is known (did'nt  
find anything on the net), whether it's really a bug (or I am making some  
stupid error), and where to report this (sending mail david korn directly  
or what??) so that it can get fixed.


thanks,

joerg

ps: in `bash' and `zsh' everything just works as expected.




-- 
Using Opera's revolutionary email client: http://www.opera.com/mail/


More information about the macports-users mailing list