我在Octave中编写了一个函数,它以从文件中读取的一行(每次一行)作为输入参数。我使用一个bash脚本从文件中逐行读取数据,并将其作为参数传递给脚本内的Octave函数。
我的bash脚本看起来像这样:
当我执行上述脚本时,Octave会抛出错误,例如:
我的bash脚本看起来像这样:
#!/bin/bash
while read line
do
octave --silent --eval 'myOctaveFunc("${line}")'
done < "inFileName"
当我执行上述脚本时,Octave会抛出错误,例如:
error: called from:
error: /usr/share/octave/3.2.3/m/miscellaneous/fullfile.m at line 43, column 11
error: evaluating argument list element number 2
error: evaluating argument list element number 1
error: /usr/libexec/octave/packages/gsl-1.0.8/i386-redhat-linux-gnu-api-v37/PKG_ADD at line 47, column 1
error: addpath: expecting all args to be character strings
error: addpath: expecting all args to be character strings
error: addpath: expecting all args to be character strings
error: addpath: expecting all args to be character strings
等等等等...
我已经能够从命令行中运行带有输入参数的Octave脚本myOctaveFunc.m
,比如helloWorld
。但当我尝试从bash脚本中运行它时,问题就出现了。
我的问题是:
1. 我该如何在bash脚本中运行Octave函数?
2. 我正在使用gvim
编辑bash脚本。当我输入调用Octave脚本的代码行时,我发现${line}
的颜色与正常情况下不同。这是因为调用Octave函数时使用了''
吗?如果是,我应该担心吗?
octave --silent --eval 'myOctaveFunc(helloWorld)'
,而应该是octave ... 'myOctaveFunc("helloWorld")'
。我尝试过octave ... 'myOctaveFunc(\"helloWorld\")'
。这在bash中使用echo
时可以正常工作,但在调用Octave脚本时失败了。 - Sriram