[comp.unix.wizards] Safely modifying a passwd file

mf@ircam.UUCP (mf) (03/03/88)

Suppose /tmp/newpasswd is the new passwd file you wish to
have (as created, say,  by a perl/csh script a program).

Say (in the script or the program)
		setenv EDITOR cp\ /tmp/newpasswd; /etc/vipw
(not to forget to escape the blank).  I.e., in csh you would
just say that, in perl you would use the "system" call.

vipw uses whatever is in the EDITOR environment variable as
the first part of a command whose argument is a temporary file
containing a copy of the original /etc/passwd and at the end of
which should be replaced by the new contents).

mf@ircam.UUCP (mf) (03/04/88)

A shorter way to do this in sh is to make use of the fact that
a simple command can be invoked while passing it an environment
variable.  So in sh one will say:
 		EDITOR="cp /tmp/newpasswd" /etc/vipw
and in the corresponding perl script
 		system('EDITOR="cp /tmp/newpasswd" /etc/vipw');