Time for action - editing the .octaverc file
1. Start Octave if you have not already done so, and open the default editor:
octave:1> edit
2. Copy the following lines into the file and save the file as
.octaverc
under the Octave home directory if you use Windows, or under the user home directory if you use GNU/Linux. (Without the line numbers, of course.) Alternatively, just use your favorite editor to create the file.PS1 (">> "); edit mode "async"
Exit the editor and restart Octave. Did the appearance of the Octave prompt change? It should look like this
>>
Note
Instead of restarting Octave every time you make changes to your setup files, you can type, for example,
octave:1> source(".octaverc")
. This will read the commands in the.octaverc
file.
What just happened?
PS1(">> ")
sets the primary prompt string in Octave to the string given. You can set it to anything you may like. To extend the preceding example given previously, PS1("\\#>> ")
will keep the command counter before the>>
string. You can test which prompt string is your favorite directly from the command prompt, that is, without editing .octaverc
. Try, for example, to use \\d
and Hello give a command, \\u
. In this book, we will stick with the default prompt string, which is \\s:\\#>
.
The command edit mode "async"
will ensure that when the edit
command is given, you can use the Octave prompt without having to close the editor first. This is not default in GNU/Linux.
Finally, note that under Windows, the behavior will be global because we instructed Octave to look for this particular .octaverc
file every time Octave is started. Under GNU/Linux, the .octaverc
is saved in the user's home directory and will therefore only affect that particular user.
More on .octaverc
The default editor can be set in .octaverc
. This can be done by adding the following line into your .octaverc
file
edit editor name of the editor
where name of the editor
is the editor. You may prefer a notepad if you use Windows, or gedit in GNU/Linux. Again, before adding this change to your .octaverc
file, you should test whether it works directly from the Octave prompt.
Later in the book, we will write script and function files. Octave will have to be instructed where to look for these files in order to read them. Octave uses a path hierarchy when searching for files, and it is important to learn how to instruct Octave to look for the files in certain directories. I recommend that you create a new directory in your home directory (Octave home directory in Windows) named octave
. You can then place your Octave files in this directory and let the interpreter search for them here.
Let us first create the directory. It is easiest simply to enter Octave and type the following:
octave1:> cd ~/ octave2:> mkdir octave
It should be clear what these commands do. Now type this:
octave3:> edit .octaverc
Add the following line into the .octaverc
file:
addpath("~/octave");
Save the file, exit the editor, and restart Octave, or use source(".octaverc")
. At the Octave prompt, type the following:
octave1:> path
You should now see that the path ~/octave/
is added to the search path. Under Windows, this path will be added for all users. The path list can be long, so you may need to scroll down (using the arrow key) to see the whole list. When you reach the end of the list, you can hit the Q key to return to Octave's command prompt.