Daniel Reeves http://ai.eecs.umich.edu/people/dreeves/mash/ MASH: Mathematica Scripting Hack (The name refers to the fact that the Mathematica kernel ought to support this, but doesn't yet...) This is a prototype of how "math -script" should work. This works the same way the perl executable does: * it takes a mathematica source file as its first argument (or from stdin if no arguments), * makes all the arguments available to the mathematica code as an array (list) called ARGV, * evaluates the code, * prints to stdout and stderr only what it is explicitly told to. The advantages of this include having a self-contained mathematica program that can be executed (with arguments) from the command line, and be used with other programs in a pipeline, etc. This is not possible with the "math < infile > outfile" method because stdin is not available, unwanted stuff gets sent to stdout, and command line arguments aren't (conveniently) available. NOTE: see TODO's in the code for discussions of known problems, future enhancements, etc. In this directory is the source file (mash.c) and the makefile. To build MASH, edit the Makefile and mash.c where indicated by "EDIT HERE". Then type make all For an illustrative example, see shuffle.m in this directory. The 2 special things about it are 1) the first line is something like #!/path/to/mash 2) it assumes that the list ARGV has been set to the command line arguments that the program was called with (which mash does). Also, note that, like using mathematica in batch mode, you need to have a plain file of just mathematica expressions -- not a notebook file. To turn a notebook into a plain ".m" file, click on each cell that you want included in the ".m" file and choose from the Cell menu: Properties -> Initialization Cell. Then when you save it should ask if you want to automatically create a package corresponding to the notebook. Say yes, and the ".m" file that's created can be used with mash like so: mash file.m or mash file.m arg1 arg2 ... If you make sure that the first line of file.m is #!/path/to/mash and make file.m executable then you can just do: file.m or file.m arg1 arg2 ... MASH can also be used to achieve the functionality of webMathematica by allowing a Mathematica program to implement CGI or be invoked easily from any programming language using a system() call. For example, see http://ai.eecs.umich.edu/people/dreeves/simplify/