Octave as executable and using argument from command line

We can write octave program just like a bash script. To do this simply create a text file and type

#!/usr/bin/octave -q
printf('hello world');

change the /usr/bin/octave with your octave executable path. The option -q makes the program does not print the usual welcome message and version of octave. More info in this page.

One thing to note is that when we take arguments from command command line, we use the built-in variable argv. This variable argv returns a cell array containing the parameters. To access the first parameter use

Note that we use curly bracket instead. This is because it is a cell array. Thanks to John W. Eaton to point this out.


One Response

  1. Of course, I got it !!!!!!!

    I spend a whole day to get this trick in octave, thanks so so so much much much

    I had this in the topic because i guess people who want to find this trick will try with the following word :
    -octave input argument script file “#! /usr/bin/octave”
    -comment recuperer les valeurs des parametres laisses en argument en entree dans un script file



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: