Use command line in matlab using ! and zsh:1: command not found: is displayed
49 views (last 30 days)
Show older comments
Chang-Soo Yun
on 9 Feb 2021
Edited: Walter Roberson
on 4 Aug 2021
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
Walter Roberson
on 9 Feb 2021
zsh is the Z shell, which is one of the successors to ksh (Korne Shell). Apple made it the default.
Accepted Answer
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
Michael
on 3 Aug 2021
@Walter Roberson I just answered in the other related issue before seeing your answer here. It seems that I stumbled across your first easiest method. I had noticed your second method in the documentation file for system.m. I did not know that each shell session could have their own PATH. Part of the issue I am dealing with is that I am trying to incorporate this into a standalone application I built in App Designer. In that case, having the users manually look up the location of airspy_rx is not preferable.
If I use your second method with the export call within system.m, will that permanantly add the path for future system calls or only update the PATH for that particulare system call?
Thanks.
Walter Roberson
on 4 Aug 2021
Edited: 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.
More Answers (0)
See Also
Categories
Find more on Help and Support in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!