Search code examples
windowsoctavestartupstartupscript

Octave- How to automatically execute commands on startup


I'm new to octave, and want to run a few commands on startup automatically every time it opens.

I typed "help startup" and saw "Octave uses the file ".octaverc". I did a bit of searching online at https://www.math.utah.edu/docs/info/octave_4.html, and saw the .octaverc file should be in the following path:

OCTAVE_HOME/lib/octave/VERSION/startup/octaverc

PROBLEM:

In that directory I don't have a startup folder, only "oct" and "site". I do see hidden files, which was my first thought since the file begins with "." character. So I then used Agent Ransack in the directory, and still nothing came up.

QUESTION:

1) Do I have to make the startup folder and octaverc file myself?

2) If so, does one, both or none have to be hidden?

3) Can it be a txt file, or does it have a special extension?

4) Do I just type the commands straight into the file or is there special formatting?

NOTE: In case I'm going about this the wrong way, there are the operations I'd like to have run on startup:

PS1('>> '), addpath('D:\Users\Me\Desktop'), clc

Thanks ahead of time for the help!!


Solution

  • Possible locations (and their differences) for octaverc files are specified in the documentation.

    In short, these are, from more general to specific:

    • octave-home/share/octave/site/m/startup/octaverc (most generic, for entire system)
    • octave-home/share/octave/version/m/startup/octaverc (to cover for more than one octave versions installed on the system, possibly requiring different startup scripts)
    • ~/.octaverc (where ~ is unix-speak for a user's home directory -- covering for user-specific startup files)
    • .octaverc files in any directory, creating specific startup conditions for specific directories

    octaverc files are effectively simple script files that are executed from most generic to most specific each time octave starts. Therefore, in the presence of conflicting commands, the more specific file can effectively be used to override the more generic behaviour.

    Octave also supports (but does not recommend) the use of the startup.m file, for matlab compatibility.

    You might also want to check out pathdef and savepath as well.

    As a more general tip, if you ever want to search for a specific keyword from the documentation (e.g. octaverc), you can type this kind of search query in duckduckgo (or google):

    octaverc site:https://octave.org/doc/interpreter/
    

    (or just download the documentation as pdf and search the pdf)