从 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 脚本
。当我尝试从 bash 脚本中运行它时,问题就出现了。myOctaveFunc.m
从命令行输入 helloWorld
我的问题是:
1. 如何在 bash 脚本中运行八度函数?
2. 我正在使用 gvim
编辑 bash 脚本。当我输入行来调用八度音程脚本时,我发现 ${line}
的颜色与正常情况下不同。这是因为 ''
用于调用八度函数吗?如果是这样,我应该担心吗?
I wrote a function in Octave that takes in a line read from a file (one line at a time) as input argument. I use a bash script to read a line at a time from the file and then pass that as argument to the octave function from within the script.
My bash script looks like so:
#!/bin/bash
while read line
do
octave --silent --eval 'myOctaveFunc("${line}")'
done < "inFileName"
When I execute above script, octave throws errors like:
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
and so on..
I have been able to run the octave script myOctaveFunc.m
with input arguments such as helloWorld
from the command line. The problem arises when I try to run it from within the bash script.
My questions are:
1. How do I get the octave function running from within the bash script?
2. I am using gvim
to edit the bash script. When I type in the line to invoke the octave script, I see that the ${line}
is colored differently as compared to normal circumstances. Is that because of the ''
used to invoke the octave function? If so, should I be worried about it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
单引号阻止 shell 替换变量:
如果 Octave 允许您使用单引号来引用字符串,它看起来会更干净一些(在双引号内,单引号没有特殊含义):
另外,从 vim 中,请确保您以 unix 格式保存文件,以便每行不以回车符结尾:
:set ff=unix
The single quotes are preventing the shell from substituting the variable:
If octave lets you use single quotes to quote strings, it will look a little cleaner (inside double quotes, single quotes have no special meaning):
Also, from vim, make sure you save the file in unix format so each line does not end with a carriage return character:
:set ff=unix