tags:

views:

183

answers:

2

I need to set an environment variable from a Mathematica notebook.

Environment["VARIABLE"]

gives the value of the variable. But is it possible to set a variable, too?

+2  A: 

I am assuming you are going to do this before you try to run an external command right? Why not instead just run "VARNAME=value; your_original_external_command" that will temporarily set the evn variable.

Yogi
+3  A: 

There's no built in function (to my knowledge), but you can just use

Run["set VAR=VALUE"]

or

!set VAR=VALUE

instead.

Edit: You'll want to see the documentation for the Run and RunThrough commands.

Iceman
"set" does not seem to work, but "export" does (I'm using bash on Mac OS X).:~ cls$ export VAR=VALUE:~ cls$ echo $VARVALUEHowever, it does not work from Mathematica.In[15]:= Run["export VAR=VALUE"]Out[15]= 0In[16]:= Environment["VAR"]Out[16]= $FailedEven if I set the variable from the command line, it cannot be retrieved with Environment[].
D-Bug