Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Here's a simple script saved in the file hello

#!/usr/local/bin/MathematicaScript -script
Print["Hello world"]

I can then run this file using math -script hello or, if the file is set to be executable, ./hello.
In Windows or OSX, run MathKernel -script hello

It prints

"Hello world"

to the terminal.

How can I change this so it does not print the quotation marks?

share|improve this question
I was using Print for outputting warnings in this superuser question. Is there a better way of printing warnings to the terminal? – Simon Jan 25 '12 at 4:17
Have a look at Message, which seems to be the usual way to handle warnings in Mathematica (I think). – David Z Jan 25 '12 at 7:50
@David: You're right, but then I need to define a new message, which seemed overkill for a short script (Messages[General] does not contain an appropriate message for me to use). – Simon Jan 25 '12 at 8:05
not that this matters, but ./hello should also work on OS X if the script is executable (and you have the right shebang) – acl Jan 25 '12 at 10:04
up vote 18 down vote accepted

Another option is to set FormatType -> OutputForm on the $Output stream:

SetOptions[ $Output, FormatType -> OutputForm ];

Or call OutputForm on the string itself:

Print[ OutputForm["Hello"] ];
share|improve this answer
+1 That's the solution I came up with after noticing the docs say that for Mathematica scripts, all output is in InputForm. (This was after posting the question) – Simon Jan 25 '12 at 4:44

WriteString is the function you're looking for. It takes two parameters, the first one being the stream you want to write to (in your case standard output, $Output), the second argument is what you want to print.

#!/usr/local/bin/MathematicaScript -script
WriteString[$Output, "Hello World!\n"]
david@thinkpad:~/temp$ ./asdf
Hello World!

If you need more general information about streams in Mathematica have a look at the corresponding help page.

share|improve this answer
+1 Thanks David. I'd never used WriteString before. – Simon Jan 25 '12 at 4:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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