This reproduces for me on SUSE 10, SUSE 11, and RedHat.
Can anyone verify they seem the same symptoms? There have
been no replies.
----- Original Message -----
From: John S. Urban
To: [email protected]
Sent: Thursday, December 08, 2011 9:30 PM
Subject: [ast-users] Corrupted output from a here document in ksh
When lines begin with the same characters as the marker used
for a here document the data generated is corrupted. This problem
appears to be long-standing but could corrupt critical data. It was
tested with
93t+ 2010-03-05
93s+ 2008-01-31
1993-12-28 r
Other common shells (csh,tcsh,bash,pdksh) do not cause the
corruption.
The simplest script that I could make to show the problem is
#!/bin/ksh
(
echo '#!/bin/ksh'
echo 'cat <<6789'
yes 6|head -500000
echo 6789
) >/tmp/test.ksh
/bin/ksh /tmp/test.ksh |uniq
Which should generate one line of output ("6").
Very surprisingly, if I take the "echo '#!/bin/ksh'" line out it works.
IA script that seems to cause errors much more reliably is the following:
#!/bin/ksh
#################################################
# usage:
# testit [pdksh|bash|sh|csh|tcsh|ash|ksh|zsh...]
# default is ksh
#################################################
/bin/rm -f /tmp/test.$XSHELL /tmp/data1 /tmp/data2
export TESTSTRING MARKER
TESTSTRING=6 MARKER=6789
TESTSTRING=67896789abcd MARKER=6789
XSHELL=${1:-ksh}
#################################################
# make script that is nothing but a cat of a here
# document. Capture what you expect the script
# into data1.
#-----------------------------------------------#
(
cat <<EOF
#!/bin/$XSHELL
#cat <<\\$MARKER
cat <<$MARKER
EOF
yes "$TESTSTRING"|head -500000|tee /tmp/data1
echo "$MARKER"
) >/tmp/test.$XSHELL
#################################################
# execute the script and put output in data2
$XSHELL /tmp/test.$XSHELL >/tmp/data2
#################################################
# compare data1 and data2
#sum /tmp/data1 /tmp/data2
uniq /tmp/data2
wc /tmp/data1 /tmp/data2
if ! cmp /tmp/data1 /tmp/data2
then
diff /tmp/data1 /tmp/data2
echo 'UNEXPECTED LINES:'
grep -n -v "^$TESTSTRING\$" /tmp/data2
else
echo data1 and data2 are SAME for $XSHELL
fi
#################################################
exit
#################################################
------------------------------------------------------------------------------
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users
_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users