4

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)?

mmal
  • 3,508
  • 2
  • 18
  • 38
  • 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 02 '14 at 01:43
  • As I have stated in the question ReadList["!source $HOME/.bashrc; echo $PATH", String] does not take any effect for me. – mmal Mar 09 '14 at 11:36

1 Answers1

1

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.

mmal
  • 3,508
  • 2
  • 18
  • 38