2.2 Quitting Octave

Shutdown is initiated with the exit or quit commands (they are equivalent). Similar to startup, Octave has a shutdown process that can be customized by user script files. During shutdown Octave will search for the script file finish.m in the function load path. Commands to save all workspace variables or cleanup temporary files may be placed there. Additional functions to execute on shutdown may be registered with atexit.

: quit
: quit cancel
: quit force
: quit ("cancel")
: quit ("force")
: quit (status)
: quit (status, "force")

Quit the current Octave session.

The exit function is an alias for quit.

If the optional integer value status is supplied, pass that value to the operating system as Octave’s exit status. The default value is zero.

When exiting, Octave will attempt to run the m-file finish.m if it exists. User commands to save the workspace or clean up temporary files may be placed in that file. Alternatively, another m-file may be scheduled to run using atexit. If an error occurs while executing the finish.m file, Octave does not exit and control is returned to the command prompt.

If the optional argument "cancel" is provided, Octave does not exit and control is returned to the command prompt. This feature allows the finish.m file to cancel the quit process.

If the user preference to request confirmation before exiting, Octave will display a dialog and give the user an option to cancel the exit process.

If the optional argument "force" is provided, no confirmation is requested, and the execution of the finish.m file is skipped.

See also: atexit.

: atexit (fcn)
: atexit (fcn, flag)

Register a function to be called when Octave exits.

For example,

function last_words ()
  disp ("Bye bye");
endfunction
atexit ("last_words");

will print the message "Bye bye" when Octave exits.

The additional argument flag will register or unregister fcn from the list of functions to be called when Octave exits. If flag is true, the function is registered, and if flag is false, it is unregistered. For example, after registering the function last_words above,

atexit ("last_words", false);

will remove the function from the list and Octave will not call last_words when it exits.

Note that atexit only removes the first occurrence of a function from the list, so if a function was placed in the list multiple times with atexit, it must also be removed from the list multiple times.

See also: quit.

© 1996–2020 John W. Eaton
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.
https://octave.org/doc/v6.3.0/Quitting-Octave.html