octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Conflicting start-up options: --eval and script.m


From: Rik
Subject: Conflicting start-up options: --eval and script.m
Date: Tue, 30 Dec 2014 09:38:40 -0800

12/30/14

I'm looking to solve bug #35318: Unclear precedence between --eval, script
file, and stdin  (https://savannah.gnu.org/bugs/?35318).  I don't think the
fix will be hard; it is more a matter of deciding what behavior we want.

Currently Octave will accept code on the command line in the form of --eval
'code ...', or a script name script.m, or directly from stdin via <
script.m.  The issue is that there is no clear idea on how to handle
multiple options.

First, multiple --evals are possible which seems reasonable.  The code is
concatenated together and then finally executed.

octave -q -f --eval 'x = pi;' --eval 'disp (x)'
 3.1416

will display the value of pi.

If a script is the last input on the line, then this is also executed. 
With a script foo.m containing "disp (e);"

octave -q -f --eval 'x = pi;' --eval 'disp (x)' foo.m
 3.1416
 2.7183

If the script is earlier then the evals then they are no longer executed.
octave -q -f  foo.m --eval 'x = pi;' --eval 'disp (x)'
 2.7183

And one can, of course, play games with which --eval statements get
executed by changing the position of the script file.

octave -q -f --eval 'x = pi' foo.m  --eval 'disp (x)'
x =  3.1416
 2.7183

Finally, one can use input redirection, but not apparently with --eval
statements.

octave -q -f < foo.m
 2.7183

But,

octave -q -f < foo.m --eval 'x = pi'
x =  3.1416

One of the simplest solutions would be to disallow the combined calling
forms by checking for it and erroring out.  Second, slightly less
appealing, would be to craft some rules about what is supposed to happen
when there are multiple arguments.  This could grow difficult because we
would need to track where in the sequence of evals we are and then run a
script and then return to executing evals.

This is related, but if I have two script files on the command line there
is no warning that one of them will not be executed.  For example, copying
foo.m over to foo2.m and changing it to display pi.

octave -qf foo.m foo2.m
 2.7183

octave -qf foo2.m foo.m
 3.1416

--Rik




reply via email to

[Prev in Thread] Current Thread [Next in Thread]