test.mma:
   #!/bin/math -script
   a = 2 + 2;
   (* do some other stuff... *)
   Print[a];
   (* do more stuff... *)
then when I make test.mma executable and run it, it should print 4 to
stdout.  Nothing else should go to stdout, just what's explicitly written.
This is the way that perl and shell scripts work and it would be very
convenient/nice/powerful for mathematica to work this way too.  For
example, you could use mathematica directly as a cgi script.
There are some issues though---things the kernel would have to do
differently when the -script option was specified:
  1) allow an input file to be specified as a command line arg
  2) ignore the first line of the input file (the #!/bin/math...)
     (this is automatic in perl and shell scripts since # is comment)
  3) allow a single command to span multiple lines
     (a way to do this would be ignore newlines except after semi-colons)
  4) not print anything to stdout unless told to
     (a stricter version of -batchoutput)
Let me know your thoughts, especially Wolfram developers.  Too bad it's
too late for version 4!
Thanks,
Daniel
--    --    --    --    --    --    --    --    --    --    --    -- 
Daniel Reeves               http://ai.eecs.umich.edu/people/dreeves/
A UNIX saleslady, Lenore,
Enjoys work, but she likes the beach more.
        She found a good way
        To combine work and play:
She sells C shells by the seashore.
> I'd like to be able to create a file like the following:
> 
> test.mma:
>    #!/bin/math -script
>    a = 2 + 2;
>    (* do some other stuff... *)
>    Print[a];
>    (* do more stuff... *)
> 
> then when I make test.mma executable and run it, it should print 4 to
> stdout.  Nothing else should go to stdout, just what's explicitly written.
> This is the way that perl and shell scripts work and it would be very
> convenient/nice/powerful for mathematica to work this way too.  For
> example, you could use mathematica directly as a cgi script.
You should have a look into MathScript <http://www.mathscript.com/>
> There are some issues though---things the kernel would have to do
> differently when the -script option was specified:
>   1) allow an input file to be specified as a command line arg
>   2) ignore the first line of the input file (the #!/bin/math...)
>      (this is automatic in perl and shell scripts since # is comment)
>   3) allow a single command to span multiple lines
>      (a way to do this would be ignore newlines except after semi-colons)
>   4) not print anything to stdout unless told to
>      (a stricter version of -batchoutput)
I'm not sure that I understand exactly what you want.  If test.mma
contains the following commands:
	a=2+2
	b=10!;
	a+b
then, running Mathematica in batch mode, only output for the first and
third commands goes to stdout:
# math -batchinput -batchoutput < test.mma
4
3628804
You can get 3) by appending a \ to long line and 4) by appending ;
Cheers,
	Paul
____________________________________________________________________ 
Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia           
Nedlands WA  6907                     mailto:pa...@physics.uwa.edu.au 
AUSTRALIA                        http://www.physics.uwa.edu.au/~paul
            God IS a weakly left-handed dice player
____________________________________________________________________
> I'd like to be able to create a file like the following:
> 
> test.mma:
>    #!/bin/math -script
>    a = 2 + 2;
>    (* do some other stuff... *)
>    Print[a];
>    (* do more stuff... *)
> 
> then when I make test.mma executable and run it, it should print 4 to
> stdout.  Nothing else should go to stdout, just what's explicitly written.
> This is the way that perl and shell scripts work and it would be very
> convenient/nice/powerful for mathematica to work this way too.  For
> example, you could use mathematica directly as a cgi script.
> 
> There are some issues though---things the kernel would have to do
> differently when the -script option was specified:
>   1) allow an input file to be specified as a command line arg
>   2) ignore the first line of the input file (the #!/bin/math...)
>      (this is automatic in perl and shell scripts since # is comment)
>   3) allow a single command to span multiple lines
>      (a way to do this would be ignore newlines except after semi-colons)
>   4) not print anything to stdout unless told to
>      (a stricter version of -batchoutput)
> 
> Let me know your thoughts, especially Wolfram developers.  Too bad it's
> too late for version 4!
You can do something linke this in Mathematica 3 and earlier if you're
working under a Unix shell.
Here is a script input file, which I denote with a file named "test.m":
[cut here]
a = 2 + 2;
Write["stdout", a];
[cut here]
Your parent shell script (what you call "test.mma") would look something
like this:
[cut here]
#!/bin/sh
$topdir=/usr/local/mathematica # path to Mathematica installation.
unsetenv DISPLAY # optional --  needed only if shell has this variable set 
math -batchinput -batchoutput < $@
[cut here]
Multiline inputs in test.m are permissible provided that the syntax
satisifes the criteria in Section A.2.10 of _The Mathematica Book_.
FrontEndExecute[FrontEnd`HelpBrowserLookup["MainBook", "A.2.10"]]
--
P.J. Hinton
Mathematica Programming Group           pa...@wolfram.com
Wolfram Research, Inc.                  http://www.wolfram.com/~paulh/
Disclaimer: Opinions expressed herein are those of the author alone.