'system' command error: " /bin/sh: -c: line 0: syntax error near unexpected token `(' "

I'm running Matlab on Mac OS. Trying to execute the following bash command, which executes without a problem in the bash shell:
join -1 3 -2 1 -o 1.3 <(sort -k3 file1.txt) file2.txt > output.txt
Using Matlab's 'system' command, and passing that string to it I get the following error:
/bin/sh: -c: line 0: syntax error near unexpected token `('
I suspect this is a problem with Matlab using the sh shell instead of Bash. Is there a work around on this?
Thanks!

回答 (3 件)

Walter Roberson
Walter Roberson 2015 年 7 月 15 日

0 投票

Notice in the documentation:
<<On UNIX, MATLAB uses a shell program to execute the given command. It determines which shell program to use by checking environment variables on your system. MATLAB first checks the MATLAB_SHELL variable, and if either empty or not defined, then checks SHELL. If SHELL is also empty or not defined, MATLAB uses /bin/sh.>>

5 件のコメント

Michael
Michael 2015 年 7 月 15 日
Thanks! I think that will do it.
Gautam Shetty
Gautam Shetty 2017 年 2 月 24 日
Getting this error while running from terminal on Mac: /Applications/MATLAB_R2016b.app/bin/matlab -r -nodesktop 'linear_regression(sample_data1.txt,1,0)'; /Applications/MATLAB_R2016b.app/bin/matlab: eval: line 1701: syntax error near unexpected token `(' /Applications/MATLAB_R2016b.app/bin/matlab: eval: line 1701: `exec "/Applications/MATLAB_R2016b.app/bin/maci64/../../Contents/MacOS/MATLAB_maci64" -r "-nodesktop" linear_regression(sample_data1.txt,1,0)'
How to set the MATLAB_SHELL env. variable and what should be the value?
Walter Roberson
Walter Roberson 2017 年 2 月 24 日
The -nodesktop needs to be before the -r. When you use -r then everything to the end of the line is part of the command.
Gautam Shetty
Gautam Shetty 2017 年 2 月 28 日
Doesn't work. Putting -nodesktop before -r opens the GUI application, doesn't run on command prompt.
Walter Roberson
Walter Roberson 2019 年 7 月 24 日
/Applications/MATLAB_R2016b.app/bin/matlab -nojvm -nodesktop -r 'linear_regression(''sample_data1.txt'',1,0)'

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

Fardowsa Halane
Fardowsa Halane 2019 年 7 月 24 日

0 投票

./matlab: line 1: syntax error near unexpected token `='
./matlab: line 1: `function p = pathdef'
Fardowsa Halane
Fardowsa Halane 2019 年 7 月 24 日

0 投票

./matlab: line 1: syntax error near unexpected token `='
./matlab: line 1: `function p = pathdef'
what do i do about this please help.

1 件のコメント

Walter Roberson
Walter Roberson 2019 年 7 月 24 日
Which directory are you cd to when you do the ./matlab at the shell prompt?

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

カテゴリ

ヘルプ センター および File ExchangeStartup and Shutdown についてさらに検索

質問済み:

2015 年 7 月 14 日

コメント済み:

2019 年 7 月 24 日

Community Treasure Hunt

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

Start Hunting!

Translated by