【发布时间】:2023-03-16 20:22:01
【问题描述】:
我在 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
等等……
我已经能够从命令行运行带有输入参数的八度脚本myOctaveFunc.m,例如helloWorld。当我尝试从 bash 脚本中运行它时,就会出现问题。
我的问题是:
1. 如何在 bash 脚本中运行 octave 函数?
2. 我正在使用gvim 来编辑bash 脚本。当我在行中键入调用 octave 脚本时,我看到 ${line} 的颜色与正常情况相比有所不同。那是因为'' 用于调用八度函数吗?如果是这样,我应该担心吗?
【问题讨论】:
-
如何在 bash 脚本之外调用您的 octave 脚本?当您在 bash 脚本中输入“echo octave --silent ...”而不是“octave --silent”时,您会看到什么?
-
@Bruno:octave 脚本的调用(在 echo 之后)类似于:
octave --silent --eval 'myOctaveFunc(helloWorld)'而它应该是octave ... 'myOctaveFunc("helloWorld")'。我试过octave ... 'myOctaveFunc(\"helloWorld\")'。这在带有echo的 bash 中可以正常工作,但在调用 octave 脚本时会失败。
标签: bash scripting command-line octave