Chet Ramey <[email protected]> writes:
> It fails because the history library requires the file to be a regular
> file. It tries to read and write atomically, so the read history function
> gets the size of the history file, allocates one big buffer to hold it,
> and reads it in one go.
Though in regard to the command "history -r file", the documentation is
rather treacherous. At first glance, and from the description of the -r
option, it seems to be just a file from which some stuff is read:
-r Read the contents of the history file and append them to
the current history list.
The key is the line buried in the preceding paragraph "If filename is
supplied, it is used as the name of the history file".
And really, that means that the effect of -r is kind of complicated and
unintuitive. The prior contents of the file are read, appended to "the
current history list", which I assume is the in-memory history, but
there seems to be an implication that all of the current history will
then (eventually) be written to the file, *prepending* the prior
in-memory history to the prior contents of the file.
And since the crucial line only applies to a subset of the history
forms, it might be clearer to split off the -anrw group with their own
header to point out the complication. E.g.
history [n]
history -c
history -d offset
history -d start-end
history -p arg [arg ...]
history -s arg [arg ...]
With no options, display the command history list with line numâ
bers. Lines listed with a * have been modified. An argument of
n lists only the last n lines. If the shell variable HISTTIMEâ
FORMAT is set and not null, it is used as a format string for
strftime(3) to display the time stamp associated with each disâ
played history entry. No intervening blank is printed between
the formatted time stamp and the history line. Options,
if supplied, have the following meanings:
-c Clear the history list by deleting all the entries.
-d offset
Delete the history entry at position offset. If offset
is negative, it is interpreted as relative to one greater
than the last history position, so negative indices count
back from the end of the history, and an index of -1
refers to the current history -d command.
-d start-end
Delete the history entries between positions start and
end, inclusive. Positive and negative values for start
and end are interpreted as described above.
-p Perform history substitution on the following args and
display the result on the standard output. Does not
store the results in the history list. Each arg must be
quoted to disable normal history expansion.
-s Store the args in the history list as a single entry.
The last command in the history list is removed before
the args are added.
history -anrw [filename]
If filename is supplied, it is used as the name of the
history file; if not, the value of HISTFILE is used.
-a Append the ``new'' history lines to the history file.
These are history lines entered since the beginning of
the current bash session, but not already appended to the
history file.
-n Read the history lines not already read from the history
file into the current history list. These are lines apâ
pended to the history file since the beginning of the
current bash session.
-r Read the contents of the history file and append them to
the current history list.
-w Write the current history list to the history file, overâ
writing the history file's contents.
If the HISTTIMEFORMAT variable is set, the time stamp informaâ
tion associated with each history entry is written to the hisâ
tory file, marked with the history comment character. When the
history file is read, lines beginning with the history comment
character followed immediately by a digit are interpreted as
timestamps for the following history entry. The return value is
0 unless an invalid option is encountered, an error occurs while
reading or writing the history file, an invalid offset is supâ
plied as an argument to -d, or the history expansion supplied as
an argument to -p fails.
Dale