Thu 17 Feb 2011 09:27:42 PM UTC, original submission:
I have been using the command
to write the interactive command history to a file as a start for a new octave script, always assuming that this command would write the history once and leave new_script.m as it is afterwards. After that I used to delete everything except the series of recent commands I was interested in (in new_script.m) and cleaned up the code only to find later that it looked like the raw command history again (and I repeatedly thought I had been really stupid because I forgot to save the changes).
It took me several weeks to realize, that what really happened was that octave wrote the history again to this new_script.m file when I quit the octave session.
So what
apparently does is to write the history to the file immediately and write it to the file again, when the octave session is closed.
This could still be a feature. However, after issuing the above command, the command
still gives
ans = /home/thorsten/.octave_hist
Interestingly, when I explicitly set the history filename with
after the history -w first_file.m command, history is written to some_other_filename when the octave session ends.
While debugging this, I found that the same happens in this example:
I.e., octave appends the content of myfile.m to the history and when the session quits, the complete history is written to myfile.m overwriting its original content.
Attached is a patch, that seems to solve the problem. However, I am quite confused by the fact, that the history file is kept within octave in two locations:
in an internal variable history_file
and
as a property of the command_history object (accessed by command_history::file and command_history::set_file)
Is this really intended? And if yes, does my patch interfere with this cunning scheme in an unwanted way?
regards
Thorsten
|