MATLAB: UNIX bash shell in an m file

bashunix

Hello,
I need to invoke a bash file from matlab which is easy enough to do. However i would like instead to write the bash code in an m file and execute the bash commands. The bash code would invoke a standalone application and pipe some things to it.
Can i simply have all bash commands in a string and use
system(string)
so it would look something like
system('path/ish -file placeholder -mode text <<XXX...
a...
b...
3...
ect ...
XXX')

Best Answer

You would have to emit newline characters in the string you submit to system(), as MATLAB is not able to construct multi-line quoted strings the way that a shell is.
If you want bash specifically, you need to invoke it by name. The shell used by system() is the $SHELL of the environment, which is not certain to be bash. On the other hand, you should be able to take advantage of the #! magic number that is recognized by unix exec*() calls, by coding the first line of path/ish as
#!bash
and then no matter which shell is your default shell, bash would be invoked to handle path/ish
sysstr = sprintf('path/ish -file placeholder -mode text <<XXX\na...\nb...\n3...\nect ...\nXXX');
system(sysstr);