Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

515
Views
MATLAB getenv unable to find some linux environment variables

I have a minor problem -- the workaround is trivial, but I wanted to learn why the problem exists at all. I have some environment variables set in .bashrc:

export FREESURFER_HOME=/usr/local/freesurfer

In my startup.m file, I tried to set the variable:

freesurfer_home=getenv('FREESURFER_HOME');

However, this call to getenv returns an empty character array. Calls to getenv within MATLAB return some environment variables (e.g., getenv('HOME')) but not others. I can see which environment variables are visible to MATLAB from the following line:

 map = java.lang.System.getenv();

I can also confirm the missing values are visible, at least within the shell, using any of

export
env
printenv

Is there an explanation for this discrepancy?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If you check process tree with system and ps f command in Matlab, you will see that it actually launches sh and executes there your command. I don't have Matlab, the same thing with Octave.

octave:1> system("ps f")
  PID TTY      STAT   TIME COMMAND
 2520 pts/0    Ss     0:00 bash
 2580 pts/0    Sl+    0:02  \_ octave
 2885 pts/0    S+     0:00      \_ sh -c ps f
 2886 pts/0    R+     0:00          \_ ps f
ans = 0

In this case variables set in .bashrc are available through getenv as I launch octave from bash. But when launching Matlab from menu launcher, the situation is different:

octave:1> system("ps f")
  PID TTY      STAT   TIME COMMAND
 3400 pts/2    Ssl+   0:01 /usr/bin/octave
 3444 pts/2    S+     0:00  \_ sh -c ps f
 3445 pts/2    R+     0:00      \_ ps f

bash has not been executed and exports from .bashrc are not set.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!