Directory listing: misc/mash/

1Makefile  2007-01-03 17:42:47  1,162 bytes
2MathIO.m  2003-06-20 20:13:55  1,017 bytes
3README  2010-08-01 16:34:08  2,541 bytes
4mash.c  2006-03-31 18:57:55  14,748 bytes
5shuffle.m  2008-08-28 20:32:56  1,086 bytes
6test.txt  2001-04-18 14:06:47  15 bytes

Contents of README file:

Daniel Reeves

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


Daniel Reeves