从bash脚本启动Matlab的错误......可能很傻

时间:2014-10-15 15:06:59

标签: linux bash matlab

我有以下bash脚本,调用下面的matlab脚本:

#!/bin/bash -x

var1=HelloWorld
var2=1:4

matlab -nosplash -nodisplay -r "testtest('$var1', $var2), exit"

function testtest(in1, in2)
if ischar(in2)
  in2 = str2num(in2)
end

in1
total = sum(in2)

return

我收到以下错误(似乎与我试图调用的函数无关):

+ var1=HelloWorld
+ var2=1:4
+ matlab -nosplash -nodisplay -r 'testtest('\''HelloWorld'\'', 1:4), exit'
MATLAB_MOD_VERSION:
MATLAB_VERSION: R2014a
LM_LICENSE_FILE (before Matlab is loaded) :
LM_LICENSE_FILE (after Matlab is loaded) : #@#
**************************************************************

... Matlab load text ...

**************************************************************
Executing: /app/matlab/R2014a/bin/matlab -nosplash -nodisplay -r testtest('HelloWorld', 1:4), exit
/app/matlab/R2014a/bin/matlab -c #@# -nosplash -nodisplay -r testtest('HelloWorld', 1:4), exit
/app/matlab/R2014a/bin/matlab: eval: line 1682: syntax error near unexpected token `)'
/app/matlab/R2014a/bin/matlab: eval: line 1682: `exec  "/work1/app/matlab/R2014a-gcc/bin/glnxa64/MATLAB"  -c #@# -nosplash -nodisplay -r "testtest('HelloWorld'," 1:4), exit'
/app/matlab/R2014a/bin/matlab: line 1682: warning: syntax errors in . or eval will cause future versions of the shell to abort as Posix requires

(注意,我用上面的#@#替换了许可证号码) 思考?

编辑:似乎不喜欢双引号中的空格。如果我摆脱了空间,它就可以了,但是我想说有一种方法可以让这个空间工作......我想对我来说并不重要。我认为这与我的单/双引号用法有关。我已经四处搜索了,据我所知,我做的事情正确......

1 个答案:

答案 0 :(得分:0)

我也认为看完回声后报价已经关闭。

经过多次挖掘后,我发现为c-shell设置了模块,默认情况下没有为bash配置模块。虽然我认为Matlab已经加载,但事实并非如此。我不得不手动为bash发送模块,从那里,上面的代码工作正常。

获取和加载模块的代码是:

. /etc/profile.d/modules.sh
modules load matlab/R#####

其中#####是matlab版本。根据我的理解,这将取决于系统。

主要参考: http://www.linuxquestions.org/questions/programming-9/script-executing-problem-module-command-not-found-761592/

感谢您的帮助。我是社区新手......我在这里找到了很多过去问题的答案!