MATLAB started as an app in OS X causes problems with "unix" function
4 次查看(过去 30 天)
显示 更早的评论
I noticed that the function "unix" acts differently, mainly in regards to my PATH variable, depending on whether I start MATLAB from the application or from Terminal.
When I start from Terminal, I get the same $PATH that I would in that Terminal window:
>> unix('echo $PATH')
/usr/local/fsl/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/Applications/Inkscape.app/Contents/Resources/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
When I start from the Application, it gets a very basic PATH from... somewhere:
>> unix('echo $PATH')
/usr/bin:/bin:/usr/sbin:/sbin
I can change my path, but it reverts the next time I use the unix function:
>> unix('source /Users/pcrutchl/.bash_profile; echo $PATH')
/usr/local/fsl/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/Applications/Inkscape.app/Contents/Resources/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin
ans =
0
>> unix('echo $PATH')
/usr/bin:/bin:/usr/sbin:/sbin
ans =
0
(To be clear: changing the path manually every time, or even initially, isn't really a solution, just an exploration of the behavior. If I could put something in startup.m to fix it, that would be fine.)
Is this known behavior? Is there a good way to get the application MATLAB to behave like the MATLAB launched from command line?
0 个评论
采纳的回答
Walter Roberson
2011-9-6
This is standard UNIX behavior, not the responsibility of MATLAB.
Each time you unix(), a new shell process is created. You do whatever to the environment variables of that shell process, but then that shell process ends before control returns to MATLAB.
You can setenv() from within MATLAB to affect the environment variables that are passed to all unix() shells open after the setenv (in that MATLAB session)
Or you can use the normal configuration files of your shell to tell it that it should execute appropriate commands each time the shell is started.
I suggest that in a terminal shell, you execute
man bash
skip the options section for now and pay serious attention starting near "The following paragraphs describe how bash executes its startup files."
2 个评论
Walter Roberson
2011-9-6
setenv() cannot execute a shell script: it can only set variables to exact strings.
Use the two-output version of unix() to capture the result of the echo $PATH, and setenv() your path to that string result.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!