Q: Mycalls ed to edit a set of files:
site=something cmty=somethingelse for i in file1 file2 file3 do ed $i << end 1,\$s/pat1/$site/g 1,\$s/pat2/$cmty/g w q end done
A: On an error - including "no matches" - ed attempts to
discard any unread commands. If you are running ed "by hand"
this has no effect, but if its input is from a file, this makes
EOF -d-of-file) the next thing it sees. You could remove the
command and you would see the same behavior, as ed automatically quits
There is a simple workaround. Unlike the
s command, the
g does not report an error if no lines match.
ed - $i << end g/pat1/s//$site/g g/pat2/s//$cmty/g w end
The - (dash) flag suppresses the two numbers
that ed normally prints when reading and writing files.
These are the number of characters in the file,
and are usually irrelevant.
[As Chris explained, the
q in the original script isn't needed.
- in comp.unix.questions on Usenet, 16 May 1989