I am trying to run bash commands from within Mathematica. Funnily enough, Mathematica seems to use a different $PATH environment than the system environment. If I try
Environment["PATH"]
or equivalently in Mathematica 10
RunProcess[$SystemShell, All, "echo $PATH"]
I get (in StandardOutput):
/usr/bin:/bin:/usr/sbin:/sbin
However, if I run echo $PATH
on my (OS X) terminal, I get (both as user and root):
/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/Library/TeX/texbin:/Library/TeX/Distributions/.DefaultTeX/Contents/Programs/texbin/:/usr/texbin:/Users/frederik/bin
which is indeed the full path. Why doesn't use Mathematica the same environmental variable? Is this expected behaviour?
EDIT
I already mentioned in the comments why this question is different from this one, but to avoid getting this question marked as a duplicate I'll repeat it here.
That thread does not deal with system environment variables (it's an unfortunate wording in the topic title) but with Mathematica environment variables. The path variable for the latter is stored in $Path
in Mathematica, while the former can be accessed by executing Environment["PATH"]
(which gives the OS system environment path). I'm really asking about the system environment variable here, but thanks to ilian and m_goldberg I realise now that it is an OS X issue.
$Path
and'PATH'
in Mma. I'm really asking about the system environment variable here, which you access withEnvironment["PATH"]
. $\endgroup$Run[]
orRunProcess[]
, it will only recognise commands inside the system wide$PATH
variable (Unix notation). What I don't understand is why it doesn't use my system path, but seems to use some default unix path which is only part of it. $\endgroup$Environment
indicate the path is system dependent ... perhaps your shell sets a user-specific environment that differs from the system default?RunProcess
also has aProcessEnvironment
option you can take advantage of. $\endgroup$