Skip to main content

scripting - How to run multiple scripts in a row from command line using the same kernel?


Here is my shell script so far (I am using MacOSX):


#!/bin/sh
math="/Applications/Mathematica.app/Contents/MacOS/MathKernel"

$math -run "< output

The two scripts I want to run in a row are script1.wl and script2.wl. The above seems to only run script1.wl


Anything obvious I am missing ?



Answer



I can't see any syntax on this page for using 2 files with the -script option (and as MB1965 points out, the help does say that only one script file can be used with the -script option). I do have some experience running WL files from the command line in Mathematica in batch mode, all of which I learned from Jens's page here.


If I create a file called "script1.wl" with the contents


x1 = 3;
x2 = 4;


and another file in the same directory, "script2.wl", with


Print[x1 + x2];
Exit[]

and then run this command from the same directory


math -noprompt -run "< output

where I've set math up as an alias in my shell to the MathKernel application, then the output file has a single line


7

Comments