Why doesn't getenv work on MAC OS X?

15 Ansichten (letzte 30 Tage)
Brando Miranda
Brando Miranda am 11 Dez. 2017
Beantwortet: Greg am 12 Dez. 2017
I was trying to get environment variables that I know exist but it returns empty arrays...is that normal?
hello =
00 empty char array
res =
00 empty char array
>>
from running
hello = getenv('hello')
res = getenv('SYSTEMROOT')
----
These are the scripts I am exactly running:
#!/bin/bash
alias matlab='/Applications/MATLAB_R2017a.app/bin/matlab -nodesktop -nosplash'
hello=hellohello
echo $hello
matlab -nodesktop -nosplash -nojvm -r "test_sh"
which runs the following:
clear;
%SLURM_JOBID = getenv('SLURM_JOBID')
%SLURM_ARRAY_TASK_ID = getenv('SLURM_ARRAY_TASK_ID')
hello = getenv('hello')
res = getenv('SYSTEMROOT')
PATH = getenv('PATH')
  2 Kommentare
Jos (10584)
Jos (10584) am 11 Dez. 2017
How do you know they exist? Apparently Matlab cannot find them. I have no problem on my Mac.
Brando Miranda
Brando Miranda am 11 Dez. 2017
what I do is run a bash script then in the bash script itself I create and echo the env variable. So it exists for sure at least in the bash script. The I run the matlab script and they are nowhere to be found:
#!/bin/bash
alias matlab='/Applications/MATLAB_R2017a.app/bin/matlab -nodesktop -nosplash'
hello=hellohello
echo $hello
matlab -nodesktop -nosplash -nojvm -r "test_sh"
which runs:
clear;
%SLURM_JOBID = getenv('SLURM_JOBID')
%SLURM_ARRAY_TASK_ID = getenv('SLURM_ARRAY_TASK_ID')
hello = getenv('hello')
res = getenv('SYSTEMROOT')
PATH = getenv('PATH')

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Greg
Greg am 12 Dez. 2017
One article I read indicates you need to call
export hello
To actually set hello as an environment variable. Otherwise, hello only exists as a "shell variable." I'm definitely not a MAC wizard, so I have no clue if that's correct, just a quick Google search.

Kategorien

Mehr zu Cluster Configuration finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by