2013-03-23 101 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