lettura simple

How to Customize Octave Prompt

In this guide, you will learn how to personalize the command prompt in Octave.

By default, the Octave prompt looks like this:

>>

To customize it, use the PS1() command.

For example, type:

PS1("Octave>>")

Now the command prompt appears as:

Octave>>

Octave also allows you to set some special functions in the prompt.

For instance, you can display the date (\d) and current time (\t) by typing:

PS1(" \\d \\t >>")

Now the prompt displays the date and time as:

Fri Mar 04 11:22:10 >>

To display a command counter, type:

PS1(" \\# >>")

Now the prompt displays a counter that increments every time you enter a command:

14 >>2+3
ans = 5
15 >>

Here are some other interesting customizations:

This command displays the current directory (\w) and the program name (\s) in the prompt:

PS1(" \\w \\s >>")

This command displays the username (\u) and hostname (\h) in the prompt:

PS1(" \\u \\h >>")

You can also write a prompt on two lines using the special command \n:

PS1(" Octave \\n >>")

You can have fun combining special characters to create the prompt you like the most.

How do you return to the default prompt?

To return to the default prompt, type the command PS1(">>") or simply restart Octave.

PS1(">>").

Note that the custom command prompt is valid only during a single session of Octave.

When Octave is restarted, the default command prompt is restored.

One tip. To load the custom prompt every time you start Octave, insert the PS1 command in a script and load the script at Octave startup. In addition to the PS1 command, there is also the PS2 command that customizes the Octave prompt for input operations when the user needs to enter a value.

If you found this guide helpful, please continue to follow us.




Report a mistake or post a question




FacebookTwitterLinkedinLinkedin