Octave normally keeps track of the commands you type so that you can
recall previous commands to edit or execute them again. When you exit
Octave, the most recent commands you have typed, up to the number
specified by the variable history_size
, are saved in a file.
When Octave starts, it loads an initial list of commands from the file
named by the variable history_file
.
Here are the commands for simple browsing and searching the history list.
On most terminals, you can also use the up and down arrow keys in place of C-p and C-n to move through the history list.
In addition to the keyboard commands for moving through the history list, Octave provides three functions for viewing, editing, and re-running chunks of commands from the history list.
If invoked with no arguments,
history
displays a list of commands that you have executed. Valid options are:
-w
file- Write the current history to the file file. If the name is omitted, use the default history file (normally ~/.octave_hist).
-r
file- Read the file file, appending its contents to the current history list. If the name is omitted, use the default history file (normally ~/.octave_hist).
- n
- Display only the most recent n lines of history.
-q
- Don't number the displayed lines of history. This is useful for cutting and pasting commands using the X Window System.
For example, to display the five most recent commands that you have typed without displaying line numbers, use the command history -q 5.
If invoked with no arguments,
edit_history
allows you to edit the history list using the editor named by the variable EDITOR. The commands to be edited are first copied to a temporary file. When you exit the editor, Octave executes the commands that remain in the file. It is often more convenient to useedit_history
to define functions rather than attempting to enter them directly on the command line. By default, the block of commands is executed as soon as you exit the editor. To avoid executing any commands, simply delete all the lines from the buffer before exiting the editor.The
edit_history
command takes two optional arguments specifying the history numbers of first and last commands to edit. For example, the commandedit_history 13extracts all the commands from the 13th through the last in the history list. The command
edit_history 13 169only extracts commands 13 through 169. Specifying a larger number for the first command than the last command reverses the list of commands before placing them in the buffer to be edited. If both arguments are omitted, the previous command in the history list is used.
See also: run_history.
Similar to
edit_history
, except that the editor is not invoked, and the commands are simply executed as they appear in the history list.See also: edit_history.
Octave also allows you customize the details of when, where, and how history is saved.
Query or set the internal variable that controls whether commands entered on the command line are saved in the history file.
When called from inside a function with the "local" option, the variable is changed locally for the function and any subroutines it calls. The original variable value is restored when exiting the function.
See also: history_control, history_file, history_size, history_timestamp_format_string.
Query or set the internal variable that specifies how commands are saved to the history list. The default value is an empty character string, but may be overridden by the environment variable OCTAVE_HISTCONTROL.
The value of
history_control
is a colon-separated list of values controlling how commands are saved on the history list. If the list of values includesignorespace
, lines which begin with a space character are not saved in the history list. A value ofignoredups
causes lines matching the previous history entry to not be saved. A value ofignoreboth
is shorthand forignorespace
andignoredups
. A value oferasedups
causes all previous lines matching the current line to be removed from the history list before that line is saved. Any value not in the above list is ignored. Ifhistory_control
is the empty string, all commands are saved on the history list, subject to the value ofsaving_history
.See also: history_file, history_size, history_timestamp_format_string, saving_history.
Query or set the internal variable that specifies the name of the file used to store command history. The default value is ~/.octave_hist, but may be overridden by the environment variable OCTAVE_HISTFILE.
See also: history_size, saving_history, history_timestamp_format_string.
Query or set the internal variable that specifies how many entries to store in the history file. The default value is
1024
, but may be overridden by the environment variable OCTAVE_HISTSIZE.See also: history_file, history_timestamp_format_string, saving_history.
Query or set the internal variable that specifies the format string for the comment line that is written to the history file when Octave exits. The format string is passed to
strftime
. The default value is"# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@HOST>"When called from inside a function with the "local" option, the variable is changed locally for the function and any subroutines it calls. The original variable value is restored when exiting the function.
See also: strftime, history_file, history_size, saving_history.
Query or set the internal variable that specifies the editor to use with the
edit_history
command. The default value is taken from the environment variable EDITOR when Octave starts. If the environment variable is not initialized, EDITOR will be set to"emacs"
.When called from inside a function with the "local" option, the variable is changed locally for the function and any subroutines it calls. The original variable value is restored when exiting the function.
See also: edit_history.