The editmap program must be run with one of
three mandatory command-line switches. This -u
switch is one of those three.
The -u command-line switch tells
editmap to open the database file in read/write
mode, to look up the key, and to replace that key's
value. If the key is not already in the database, both the key and
its value are added to the database:
% editmap -u dbtype dbfile sought-key new-value
If the dbfile lacks read/write permission,
the following error will print and editmap will
exit with an EX_IOERR (EX_IOERR) exit value:
editmap: error opening type dbtype map dbfile: Permission denied
If the sought-key is found, its value is
replaced with the new-value. If the
sought-key is not found, both the key and value
are added to the database.
Be careful updating aliases-style database
files. If you omit the -N command-line switch with
such files, your key will not be found even if it exists, and thus
the key and value will wrongly, and silently, update the database. To
illustrate, consider this alias:
bob: bob@another.host.domain
If bob moves, you might want to directly edit this
aliases-style database to change his address.
Here is the correct way to update:
% editmap -N -q hash offsite-aliases bob
bob@another.host.domain
% editmap -N -u hash offsite-aliases bob bob@new.domain
% editmap -N -q hash offsite-aliases bob
bob@new.domain
Here, because offsite-aliases is an
aliases-style database, we use the
-N command-line switch with all commands. The
first and last commands look up (with -q)
bob in the database. The second command changes
the address for bob.
In the following we omit the -N from the update
command. This is the wrong way to update such a database:
% editmap -N -q hash offsite-aliases bob
bob@another.host.domain
% editmap -u hash offsite-aliases bob bob@new.domain note no -N
% editmap -N -q hash offsite-aliases bob
bob@another.host.domain note no update
% editmap -q hash offsite-aliases bob
bob@new.domain note bogus update
The key bob is in the database, but with a
trailing null byte. The update command (the -u)
omits the -N and so omits a trailing null byte
from the looked-up key. As a result, the key is not found, so the key
and value are wrongly added as a new key/value pair to the database.
The last two commands illustrate the problem. The first correctly
uses the -N and finds that the value was not
updated. The second incorrectly omits the -N and
finds that another bob (the one without the
trailing null byte) got the update.