MATLAB Answers

Use command line in matlab using ! and zsh:1: command not found: is displayed

51 views (last 30 days)
Hi
I'm using MATLAB 2020b and Big sur OSX
before catalina version, in my memory...
I was using well with ! for call mac command line
but now in big sur when I use ! and matlab display zsh:1: command not found: brew or other package!
so...how can I solve it?
  3 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 9 Feb 2021
Open terminal on the Mac. Give the command
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
This is not MATLAB specific: you happen to be asking to execute commands that need the third-party package "brew" installed.
  8 Comments
Walter Roberson
Walter Roberson on 4 Aug 2021
The shell export command only affects the environment for that shell and the subprocesses of the shell, and each system() call is a different process.
At the MATLAB level you can do things like
setenv('PATH', getenv('PATH')+":/usr/local/bin")
and that should affect anything started using system() or the ! operator. But that does not tell you where your executable is.
To locate the executable, you can try:
[status, msg] = system('exec -a -ksh /bin/ksh -c "which airspy_rx"');
if status == 0
airpath = string(regexprep(msg, '\r?\n', ''));
setenv('PATH', getenv('PATH')+":"+airpath);
else
error('Failed to locate airspy_rx because "%s"', msg);
end
This should work if the user has ksh or zsh configured as their login shell, and someone has configured the appropriate configuration files so that airspy_rx is normally on their path when they log in.
If they happen to have configured bash instead, then
bash -l -c "which airspy_rx"
would be appropriate.. you could try that within the "else".
But at some point you are going to encounter a user whose shell configuration does not have the executable on the path, and you going to have to uigetfile() or something similar.
You might want to use the MATLAB preferences system https://www.mathworks.com/help/matlab/ref/setpref.html to remember the setting for each user.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!