compilation using matlab and bash scripting

I have a bash script where I invoke the matlab compiler with some arguments, that is mcc ${MCC_ARGUMENTS}. Now I would like to issue this command from matlab, but still inside the bash script. Something like:
MCC_ARGUMENTS="..." # here I set arguments for mcc
matlab -nodisplay -r "mcc ${MCC_ARGUMENTS}, quit"
However this solution doesn't work, it seems MCC_ARGUMENTS is not evaluated.

Risposte (1)

I think your decorations around MCC_ARGUMENTS are wrong, and you need to escape the quotes since you need them in the actual command. For example,
#!/bin/bash
MCC_ARGUMENTS="-a -b -c"
MATLAB_STRING="matlab -nodisplay -r \"mcc $MCC_ARGUMENTS, quit\""
echo $MATLAB_STRING
You can take out the "echo" to execute the command.

5 Commenti

With echo it works, but if I simply take out the "echo" I get the following error:
'eval: 1: Syntax error: Unterminated quoted string
Currently I use different solution:
echo "mcc ${MCC_ARGUMENTS}; quit" > f.m
matlab -nodisplay -r f
but I would prefer to not create additional file.
What are the actual arguments you are setting? Do they have quotes in them? You may need to escape those.
MCC_ARGUMENTS="-o ${NAME} -W main:${NAME} -T link:exe -d ${BUILDDEST} -w enable:specified_file_mismatch -w enable:repeated_file -w enable:switch_ignored -w enable:missing_lib_sentinel -v ${SRC} -R \'-nodisplay\' -R \'-singleCompThread\' ${INCLUDES} ${EXTERNALS}"
Where $NAME is input ($NAME="$1"), and other variables were set to point to patches (no quoted strings inside).
hmmm. Nothing pops out there. If you echo out MCC_ARGUMENTS, does it look right?
Seems something in the expansion process is eating a quote.
FWIW when I've run into this kind of thing the only way I've been able to figure out where quotes are being eaten is to gradually "reveal" the line or break it up into smaller segments, then put it all together at once, like
ARG1 = stuff
ARG2 = "more stuff"
then at the end you do
MY_BIG_COMMAND = ARG1 ARG2 ARG3

Accedi per commentare.

Categorie

Richiesto:

il 22 Feb 2012

Community Treasure Hunt

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

Start Hunting!

Translated by