Getting started with octave – Reading commands from a script file

Octave commands can be saved in a file and evaluated by loading the file using source.

For instance, let hello.m be the text file containing two lines (the first line is a comment)

# my first Octave program
disp('Hello, World!')

If you type source hello.m at an Octave command prompt you will get

>> source hello.m
Hello, World!

Note that a script file doesn’t necessarily have to have the extension .m.

if you want to reproduce, please indicate the source:
Getting started with octave – Reading commands from a script file - CodeDay