Can I call a bash shell script (using cygwin) through matlab?

I want to call a bash shell script glider_merge.sh from glider_boat_check.m. I need to pass arguments such as location, unit, and year. Do I have to define these in the shell script or can I pass them through matlab?
The glider_merge.sh script merges science and flight data into a .dat file and .mat file. I want to just be able to open glider_boat_check.m, press run which executes glider_merge.sh and then glider_boat_check.m opens the .mat output file and does more diagnostics.
I am (brand) new to UNIX and haven't had much experience with matlab either. Any suggestions would help greatly.

回答 (1 件)

Titus Edelhofer
Titus Edelhofer 2015 年 6 月 1 日

0 投票

Hi,
you can use the system function to call your shell script. Something like
location = 'Germany';
system(['yourshellscript.sh ' location]);
This way you pass location as parameter to the shell script.
Titus

4 件のコメント

Brita Irving
Brita Irving 2015 年 6 月 2 日
Thanks for your advice, I found something that works to run the shell script
>> system('C:\cygwin64\bin\bash --login -c "C:/cygwin64/home/bkirving/gliders/ProcArchive/glider_merge.sh"');
I had to update all the paths in glider_merge.sh to full paths so that matlab could work. However, I still haven't been able to pass parameters. I tried >> system(['C:\cygwin64\bin\bash --login -c "C:/cygwin64/home/bkirving/gliders/ProcArchive/glider_merge.sh"' location unit year]); but that does not work.
Any further advice would be great, thanks!
Ken Atwell
Ken Atwell 2015 年 6 月 3 日
Are 'location', 'unit', and 'year' MATLAB variables that are already chars? You may be to create a string and then call system on that string:
str = ['C:\cygwin64\bin\bash --login -c "C:/cygwin64/home/bkirving/gliders/ProcArchive/glider_merge.sh" ' location ' ' unit ' ' year];
system(str)
Titus Edelhofer
Titus Edelhofer 2015 年 6 月 3 日
And use num2str(year), if year is a number (double) and not a string ...
Chris Endemann
Chris Endemann 2019 年 1 月 31 日
編集済み: Chris Endemann 2019 年 1 月 31 日
I was just working from this solution, and found that the final answer is slightly incorrect. The final double quote should come after the input argument list, i.e.:
str = ['C:\cygwin64\bin\bash --login -c "C:/cygwin64/home/bkirving/gliders/ProcArchive/glider_merge.sh ' location ' ' unit ' ' year '"'];
system(str)

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeEntering Commands についてさらに検索

質問済み:

2015 年 6 月 1 日

編集済み:

2019 年 1 月 31 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by