How to invoke octave script in unix shell

青春壹個敷衍的年華 提交于 2019-11-30 19:34:23

问题


I have written an octave script file (.m)

If anyone could point me out on how to run octave scripts on unix shell that would be really helpful. I do not want to execute the script by invoking octave program.

I am new to unix and octave.

Thanks in advance


回答1:


Yes, of course you can write an Octave program. Like so:

$ cat octave_program 
#!/usr/bin/env octave
## Never forget your licence at the top of the files.
1;

function [rv] = main (argv)
  disp ("hello world");
  rv = 0;
  return;
endfunction

main (argv);

$ chmod a+x octave_program # add executable permissions
$ ./octave_program 
hello world

There's a couple of things important for an Octave program:

  1. the first statement cannot be a function declaration. In all my programs, the first statements are loading of necessary packages. If you don't have packages, it is common to use 1;

  2. a she-bang line. That's the first line of your program which tells you how to run your program. If you know where Octave will be installed, you can use #!/usr/bin/octave but using #!/usr/bin/env octave will be more portable and flexible.

  3. your program needs executable permissions



来源:https://stackoverflow.com/questions/35669024/how-to-invoke-octave-script-in-unix-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!