A/UX: "ed" and Filenames


Article Change History
----------------------
08/31/92 - REVIEWED
* For technical accuracy.


Some A/UX users have misunderstood how the "ed" program works in terms of
remembering file names.

In the following illustration the user tries to
edit a file named "testfile", insert the contents of the password file, and
update the original file.

$ ed - testfile
P Get a prompt
* 3 The original script inserted a file at line 3
-r /etc/passwd Include the password file
w Try and update the original
? 'ed' has a problem!
h Explain it.
cannot open file It can't write to the /etc/passwd file
f Show the "current" file
/etc/passwd It's set to /etc/passwd not to "testfile"!
q
$

The user assumed that the file name at the end should be "testfile" and not
"/etc/passwd".

The manual entry for ed(1) gives an explanation for this problem. The
currently remembered filename can be set when you use certain commands
within ed--"r FILE", for example. There are some restrictions; the
currently remembered filename is only changed when FILE is the very first
filename mentioned since ed was invoked. So when you add a command like

f testfile

directly after invoking ed, the currently remembered filename will be
"testfile" until you specify otherwise. This way the "r" command will not
set the filename.

The ed(1) manual pages do mention some restriction on the currently
remembered filename. Paragraph of ($) r file command, states

"The currently remembered filename is NOT changed unless the file is the
very first filename mentioned since ed was invoked."


Published Date: Feb 18, 2012