Reputation: 73
I have a octave script (script.m) file with the following code:
if length(argv()) > 0
s = argv(){1};
else
s = "";
In octave command window, pwd is set to the script directory. From command window, how can I run script.m with one, two or no arguments?
I am using Octave (GUI) in windows.
Upvotes: 0
Views: 5507
Reputation: 8091
An endif
is missing at the end but here we go:
if length(argv()) > 0
s = argv(){1};
else
s = "";
endif
s
With no argument:
$ octave script.m
s =
With one argument:
$ octave script.m foobar
s = foobar
With two arguments (the second goes to nirvana because you don't use it in your script):
$ octave script.m foobar baz
s = foobar
Upvotes: 1