If I start an octave interactive shell, I can type:
octave:1> function y = foo(x)
> y = x + 2;
> endfunction
octave:2> foo(7)
ans = 9
The interpreter knows to wait for the rest of the function definition.
However, if I do
octave:1> eval("function y = foo(x)");
octave:2> eval("y = x + 2;");
octave:3> eval("endfunction");
it evaluates each line as if it were alone. So it defines a function foo which does nothing, and gives errors for the second two lines.
Is there any way to get eval to operate the same as the interpreter? Ultimately, I would like to create an octave script which executes another script, but is able to do other things in between. Is there any way to tell eval to wait for the rest of the command (the way the interactive environment does)? Alternatively, is there a way to feed commands to the interactive interpreter programmatically?
Thank you.