Created attachment 160478 [details]
ex string substutition bug demonstration
ex/vi implementations in 10.2-RELEASE, and 11.0-CURRENT have issues with string substitution when the phrase that would be replaced with a new one appears in a single line more than once.
This phenomena is visible when ex(1) is invoked with -s and -c options. Attached text file includes step by step demonstration of the problem. The last command in the attached file always fails.
Problem is most probably visible in older versions of FreeBSD as well, I have only tested on these two systems.
Problem reproduced on Debian GNU/Linux 8.1.0-amd64, on which nvi can be installed via apt-get. "ve" command output for "ex"
Version nvi-1.81.6 (2007-11-18) The CSRG, University of California, Berkeley.
uname -a output for Debian GNU/Linux
Linux Debian 3.16.0-4-amd64 #1 Debian 3.16.7-ckt11-1+deb8u3 (2015-08-04) x86_64 GNU/Linux
Problem persists with nvi 2.1.3 that comes with FreeBSD 11.0-RELEASE
/tmp/vi.4UCmUoap3c: new file: line 1
Version 2.1.3 (2015-04-08) The CSRG, University of California, Berkeley.
~ % uname -a
FreeBSD fbsd 11.0-RELEASE-p1 FreeBSD 11.0-RELEASE-p1 #0 r306420: Thu Sep 29 01:43:23 UTC 2016 email@example.com:/usr/obj/usr/src/sys/GENERIC amd64