Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

521
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda