Try the following:
echo 'matlab -nojvm -r "p=setpath(/mydirectory/);addpath(p);myscript;exit"' |sh &
External single quotes protect internal double quotes, so sh
does not see parentheses.
Is there a reason you can't just:
matlab -nojvm -r "p=setpath(/mydirectory/);addpath(p);myscript;exit" &
or perhaps:
matlab -nojvm -r "p=setpath(/mydirectory/);addpath(p);myscript;exit" </dev/null &
source share