从bash脚本中将参数传递给octave函数

Sri*_*ram 7 bash scripting command-line octave

我在Octave中编写了一个函数,它从文件中读取一行(一次一行)作为输入参数.我使用bash脚本从文件中一次读取一行,然后将其作为参数传递给脚本中的八度函数.

我的bash脚本看起来像这样:

#!/bin/bash  

while read line
do
  octave --silent --eval 'myOctaveFunc("${line}")'
done < "inFileName"
Run Code Online (Sandbox Code Playgroud)

当我执行上面的脚本时,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
Run Code Online (Sandbox Code Playgroud)

等等..

我已经能够myOctaveFunc.m使用输入参数运行八度脚本,例如helloWorld从命令行.当我尝试从bash脚本中运行它时出现问题.

我的问题是:
1.如何在bash脚本中运行八度函数?
2.我gvim用来编辑bash脚本.当我输入行来调用八度音阶时,我发现${line}与正常情况相比,它的颜色不同.那是因为''用于调用八度功能吗?如果是这样,我应该担心吗?

gle*_*man 11

单引号阻止shell替换变量:

octave --silent --eval "myOctaveFunc(\"$line\")"
Run Code Online (Sandbox Code Playgroud)

如果octave允许你使用单引号引用字符串,它看起来会更清晰(在双引号内,单引号没有特殊含义):

octave --silent --eval "myOctaveFunc('$line')"
Run Code Online (Sandbox Code Playgroud)

此外,从vim,请确保以unix格式保存文件,以便每行不以回车符结束: :set ff=unix