Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在unixshell中调用octave脚本_Shell_Scripting_Command Line Interface_Sh_Octave - Fatal编程技术网

如何在unixshell中调用octave脚本

如何在unixshell中调用octave脚本,shell,scripting,command-line-interface,sh,octave,Shell,Scripting,Command Line Interface,Sh,Octave,我已经编写了一个八度脚本文件(.m) 如果有人能告诉我如何在unixshell上运行octave脚本,那将非常有帮助。我不想通过调用octave程序来执行脚本 我不熟悉unix和octave 提前谢谢是的,当然你可以写一个八度程序。像这样: $ cat octave_program #!/usr/bin/env octave ## Never forget your licence at the top of the files. 1; function [rv] = main (argv)

我已经编写了一个八度脚本文件(.m)

如果有人能告诉我如何在unixshell上运行octave脚本,那将非常有帮助。我不想通过调用octave程序来执行脚本

我不熟悉unix和octave


提前谢谢

是的,当然你可以写一个八度程序。像这样:

$ 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
对于八度音阶的节目来说,有两件事很重要:

  • 第一条语句不能是函数声明。在我所有的程序中,第一个语句是加载必要的包。如果没有软件包,通常使用
    1

  • a。这是程序的第一行,它告诉您如何运行程序。如果您知道倍频程将安装在哪里,您可以使用
    #/usr/bin/octave
    但使用
    #/usr/bin/env倍频程
    将更加便携和灵活

  • 您的程序需要可执行权限


  • 您打算如何在不运行octave的情况下运行octave脚本?提示:你不能。但是,您可以调用octave来运行脚本:
    octave-q script.m
    应该使用“安静”模式,octave不会转储额外的垃圾。@AndrasDeak与从任何其他语言调用脚本的方式相同(可能除了Matlab和R)。如果操作正确,您不需要在命令行上实际指定
    octave
    。它只是不够透明,但仍然是八度音阶调用运行脚本。@AndrasDeak考虑到语言和问题,我认为这正是OP的意思。不必在命令行中指定它。就像从用这些语言编写的
    /usr/bin
    调用东西时,不必在命令行中指定bash、python、perl或ruby一样。@carandraug我想你是对的。公平地说,我总是显式地调用脚本:)