#! /bin/sh # # A bug in sed with one-line fix and a workaround. # # This demonstrates a bug in sed on Ultrix version 3.0, 4.3-Tahoe, # Unix-PC (system V) -- probably a lot of versions. # # Unix vendors take note -- SUN and NeXT have *already* fixed the bug... # # THE BUG: # # The bug causes only the odd input lines to be printed in the script below. # # According to the manual, the condition for branching with the "t" command # should be set by successful substitution on the *current* line and cleared # by either branching or reading a new line. What appears to happen is that # the flag is not cleared by reading a new line, so the branch is taken on # every even numbered line (causing it not to print). # # THE WORKAROUND: # # Putting an additional "t" command at the end of the script to clear the # flag is probably the shortest workaround. # # THE FIX: # # If you have sources, the fix appears to be quite trivial: the variable # sflag is set to 1 when a substitute happens, to zero after a TCOM # happens, but is never set to zero when a new line is read. A good # place to do that seems to be where the line number is incremented # in function gline() just after lnum++. # # Corey Satten, corey@cac.washington.edu, 9/28/89. echo ' one two three four' | sed -n 's/NeVeR FiNd So DoNt BrAnCh/&/ t s/./&/p '