[comp.sources.bugs] inconsistent behavior of sed

glen@proexam.UUCP (Glen Brydon) (07/09/89)

Upon upgrading to 4.0.3 of SunOS (yes, another version of bsd unix)
we noticed that one of our many shell scripts stopped working.
Upon examination we found that it was a sed script which did the
following:

	sed 's/.*/&/p;d'  (this is a minimal condensation)

It seems obvious to me that this should simply pass all information,
however, some versions of sed actually delete. This seems to be always
true of sysV sed and recently true of bsd sed (post 4.0 sunOS).

Is there anyone out there who has noticed this or disagrees with my
acessment of the situation (i.e. sysV sed has a bug!).

Please email me and I will summarize to the net.

Glen Brydon (glen@proexam.uucp)

tmal@cl.cam.ac.uk (Mark Lomas) (07/12/89)

In article <377@proexam.UUCP> glen@proexam.UUCP (Glen Brydon) writes:
>	sed 's/.*/&/p;d'  (this is a minimal condensation)
>
>It seems obvious to me that this should simply pass all information,
>however, some versions of sed actually delete. This seems to be always
>true of sysV sed and recently true of bsd sed (post 4.0 sunOS).

The manual entry for sed which is supplied with HP-UX, a System V
derivative, indicates that this change in behaviour is deliberate.

In previous versions of sed the `p' flag at the end of a substitute
command caused the result of the substitution to be printed.  In the
current version the state of the `-n' switch is also checked.  Only
if output is disabled by default will the `p' flag have any effect.

This means that the example which you gave may be corrected by adding
the `-n' switch to the command line:

	sed -n 's/.*/&/p;d'

		Mark Lomas (tmal@cl.cam.ac.uk)