Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to run external command from Mathematica. For this I need to have bash environment configured via reading the content of ${HOME}/.bashrc file. When I execute the following code in Mathematica notebook

ReadList["!echo $PATH", String]

the content of PATH variable is not set as it is in ${HOME}/.bashrc. The same happens when I explicitly load bash configuration file

ReadList["!source ${HOME}/.bashrc; echo $PATH", String]

(strictly speaking the above command makes no effect!). So the question is: is it possible to load the configuration stored in .bashrc file in Mathematica external call under the Linux system (of course without explicitly setting e.g. mentioned PATH variable is not a solution for me)?

share|improve this question
try ReadList["!printenv",String] start by figuring aout what shell is running and what environment is avaialable. – george2079 Dec 28 '13 at 13:45
Why not use Run? – Mike Honeychurch Dec 28 '13 at 22:50
Played with this a bit: you can reveal the actual shell with this: Readlist["!/bin/ps -p $$"] -- In my case I've got the bourne shell /bin/sh. printenv incorrectly shows the SHELL variable inherited from the shell used to invoke mathematica. So.. make shure your bashrc doesnt do anything incompatable with plain /bin/sh .. – george2079 Dec 30 '13 at 19:18
I don't understand the question. ReadList["!echo $PATH", String] gives me {"/usr/bin:/bin:/usr/sbin:/sbin"} which is expected since it did not read the contents of my bashrc file. If I do ReadList["!source $HOME/.bash_profile; echo $PATH", String] then I get all of the path that I have set up in there. – jmlopez Jan 2 '14 at 1:43
As I have stated in the question ReadList["!source $HOME/.bashrc; echo $PATH", String] does not take any effect for me. – mmal Mar 9 '14 at 11:36
up vote 0 down vote accepted

The solution for me is to start the Mathematica form a terminal, instead of Gnome launcher. Then the bash environment, when ReadList is executed, will be inherited from the shell itself.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.