2013-03-23 139 views
2

比方说,我有这样的MATLAB功能MATLAB bash脚本

function a = testfun(filename) 
% do something with file contents and create some variable a 
disp(a); 

我想有一个在Cygwin运行shell脚本如下:

./testscript.sh <inputforfunction.txt> outputoffunction.txt 

输入文件将包含数据I需要。 运行此命令后,输出文件将包含运行testfun(filename)的结果。

到目前为止,我可以将输出写入文件outputoffunction.txt。

问题是我想读取文件名“inputforfunction.txt”。

我能够在文件内容但不是文件名阅读,任何提示吗? 谢谢!

回答

0

为什么不把文件作为参数传递给bash脚本?

./testscript.sh inputforfunction.txt > outputoffunction.txt 

在脚本中,您可以访问$1 - 它会评估为'inputforfunction.txt'

+0

感谢您的建议,但我知道这个选项,不幸的是,我被限制重定向输入和输出。 – lyes 2013-03-24 17:27:33

+0

@ LyesKhalil - 你有可能重定向'echo inputforfunction.txt'吗? – Shai 2013-03-24 17:50:18

+0

不知道我有什么意思 – lyes 2013-03-24 20:02:11

0
read file_name 
./testscript.sh < $file_name > outputoffunction.txt