I'm on linux using Mathematica 12.1.1 in text mode, i.e. command line.

How do I execute a script (which for me just means a text file with valid Mathematica expressions in it), display the results and keep the interpreter open?

If I do

math < myfile.m

mathematica will execute the content of myfile.m but at the end will quit. I'd like to be able to perform further computations on the results after executing everything so I'd like to keep the interpreter open. How do I do that?

Usually interpreters have command line switches for this:

for example, in Maple, I'd do

maple -F < myfile.mpl

or in gnuplot the same thing can be achieved via

gnuplot myfile.mpl -

So it's a bit odd if this would be completely impossible in mathematica.


1 Answer 1


Quote from the init.m documentation: "To specify another file to be used for kernel initialization in addition to init.m, use the kernel command-line option -initfile file, where file is the additional initialization file."

So try this in the Linux command line:

./math -initfile myfile.m

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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