Go to the first, previous, next, last section, table of contents.


Command History Functions

Octave provides three functions for viewing, editing, and re-running chunks of commands from the history list.

Command: history options
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 named file. If the name is omitted, use the default history file (normally `~/.octave_hist').
-r file
Read the named file, replacing the current history list with its contents. If the name is omitted, use the default history file (normally `~/.octave_hist').
N
Only display the most recent N lines of history.
-q
Don't number the displayed lines of history. This is useful for cutting and pasting commands if you are 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'.

Command: edit_history options
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 use edit_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 command

edit_history 13

extracts all the commands from the 13th through the last in the history list. The command

edit_history 13 169

only 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.

Built-in Variable: EDITOR
A string naming the editor to use with the edit_history command. If the environment variable EDITOR is set when Octave starts, its value is used as the default. Otherwise, EDITOR is set to "vi".

Command: 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.

Built-in Variable: history_file
This variable 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.

Built-in Variable: history_size
This variable 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.

Built-in Variable: saving_history
If the value of saving_history is "true", command entered on the command line are saved in the file specified by the variable history_file.

Command: diary
The diary command allows you to create a list of all commands and the output they produce, mixed together just as you see them on your terminal.

For example, the command

diary on

tells Octave to start recording your session in a file called `diary' in your current working directory. To give Octave the name of the file write to, use the a command like

diary my-diary.txt

Then Octave will write all of your commands to the file `my-diary.txt'.

To stop recording your session, use the command

diary off

Without any arguments, diary toggles the current diary state.

Command: echo options
Control whether commands are displayed as they are executed. Valid options are:

on
Enable echoing of commands as they are executed in script files.
off
Disable echoing of commands as they are executed in script files.
on all
Enable echoing of commands as they are executed in script files and functions.
off all
Disable echoing of commands as they are executed in script files and functions.

If invoked without any arguments, echo toggles the current echo state.

Built-in Variable: echo_executing_commands


Go to the first, previous, next, last section, table of contents.