[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: command line call
From: |
Mike Miller |
Subject: |
Re: command line call |
Date: |
Fri, 7 Aug 2015 19:09:26 -0400 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
On Fri, Aug 07, 2015 at 13:06:19 -0400, dgw wrote:
> Hi,
>
> I have a question about a difference, which I noticed in how octave
> treats functions vs. scripts, when calling from the command line.
> (particulars: this is tested on octave 3.8.1 on a mac running 10.9.3).
> When I call:
>
> octave myscript
>
> octave will run all of the commands in the script and then exit.
> Conversely, if I call
>
> octave myfunction
>
> octave will simply start and quit without running the commands inside.
>
> This behavior seems to contradict the following documentation:
> https://www.gnu.org/software/octave/doc/interpreter/Invoking-Octave-from-the-Command-Line.html#Invoking-Octave-from-the-Command-Line
>
> Is this intended? Should the documentation be reworded?
It doesn't look contradictory to me, but this has been asked before many
times. Let's look at your examples:
> myscript:
> % myscript
> %
> disp('Running')
Running this script executes a single command, disp('Running'), which
displays the string.
> myfunction:
> function myfunction
> % myfunction
> %
> disp('Running')
This is a function file, which means if you run "myfunction" as a
command in the Octave interpreter, it will execute the function body as
you might expect.
But running this file as a script simply executes the same as if you
pasted it into the Octave shell. The end result is that a function
called "myfunction" has been *defined* but nothing has executed it.
If your script was instead:
function myfunction
disp('Running')
end
myfunction
Now it will finish the definition of the function, and then call it.
HTH,
--
mike