3
$\begingroup$

What I'd like to do is to have a Mathematica script use some user-defined bash functions before scheduling some calculations on the results generated by by these functions. Since I have them written in bash, I use

$SystemShell = "/bin/bash"

and get the error

Set::wrsym: Symbol $SystemShell is Protected. >>

and all subsequent lines naturally crash if they need bash to work. Funny thing is, if I go back and Shift+Enter the same line again,

$SystemShell = "/bin/bash"

this and all subsequent lines work fine.

I am doing this on the login node of a small cluster, using PUTTY+XMing to forward X11 to my Windows system so I can use the GUI. So, to summarize, changing the SystemShell fails if it is part of the first set of commands being Shift+Enter-ed together, but not on subsequent attempts. Could someone help me understand what is happening and how I could get this to work in one go so that I can make a .m script out of it and submit it as a job to the compute nodes? Thanks a bunch!

Sample script:

$SystemShell = "/bin/bash"
bash = StartProcess[$SystemShell]
WriteLine[bash, "! submitjob () {    
some code
}"]; ReadString[bash, EndOfBuffer]
$\endgroup$
  • $\begingroup$ When I get a Protected warning the first thing I try, if I really do want to change it, is Unprotect $\endgroup$ – Bill Jul 10 '16 at 17:47
  • $\begingroup$ Thanks! I didn't know about this feature. It's puzzling why it's protected on the first go, but not the second time, though. Is this unique to my situation, or is someone able to reproduce this? $\endgroup$ – Tamaghna Jul 10 '16 at 22:35
3
$\begingroup$

There is no obligation to use the $SystemShell symbol. It does not have any special meaning and one could just as well do

myShell = "/bin/bash";
bash = StartProcess[myShell]

$SystemShell is defined only for convenience, and on Windows it is always "cmd" while on Unix it is always "/bin/sh". Of course a different shell can be launched like any other executable.

As for the Protected attribute behavior observed, that is a consequence of how the kernel autoloading mechanism works.

Initially $SystemShell has only a special ActivateLoad definition (which can be seen by evaluating OwnValues[$SystemShell] in a fresh session) that allows the implementation to be loaded at first use.

It is very common for a symbol to get protected again after all its real definitions are read in, though this is not the case for $SystemShell.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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