Accessing shell environment variables in MATLAB under Ubuntu Linux 10.04
조회 수: 6 (최근 30일)
이전 댓글 표시
I am running MATLAB R2011a under Ubuntu 10.04. When I launch matlab by typing matlab& in a terminal window, I can access shell environment variables that have been set in /etc/profile.
However, when I launch MATLAB from the menu or from an icon (in either case, the .desktop command is "matlab -desktop"), these shell variables are not set.
How can I launch MATLAB from menus or icons and have it see the environment variables?
Thanks.
댓글 수: 0
답변 (4개)
Ty Watkins
2022년 1월 21일
Ran in to this same issue when I tried to create a menu launch for Matlab on RHEL7 running KDE Plasma. The issue is that if not run from a terminal, it will launch with a non-interative, non-login environment. Instead of going in and trying to move the additoins to the $PATH variable in the .bashrc above the logic that kicks a non-interative bash session out, a simple way is to start a new bash environment similar to what @Walter Roberson posed as his solution. However, I would recommend starting it as an interactive shell and not a login shell. There's not going to be a large difference between the two. The part that was missing is the you have to add the '-c' flag before the string containing the command you want to run. Change the command to the following and you should be good to go.
$SHELL -i -c 'matlab -desktop'
This should load all the environment variables that get set for a normal interactive terminal.
댓글 수: 0
Walter Roberson
2011년 7월 29일
Change the menu or icon so that the command for it is
$SHELL -l "matlab -desktop"
where you should probably replace $SHELL with the name of your preferred shell.
댓글 수: 0
Igor Izyurov
2021년 8월 16일
10 years later another Matlab-on-Linux user [me] was having the same question.
I'm writing the answer for the history. The solution for any application is described here: https://askubuntu.com/questions/542152/desktop-file-with-bashrc-environment
In short, ~/.bashrc should be modified so, that all nessessary exporting occurs before these lines:
# Matlab, being run from Launcher won't see this:
export MATLABROOT=/usr/local/MATLAB/R2021a
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
# But will see this:
export MATLABROOT=/usr/local/MATLAB/R2021a
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!