Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am running Mathematica 9 on a linux machine and I've encountered the following behaviour that I am trying to understand. When I'm editing multiple source (.m) files using mathematica saving adds a new line which reads

(* ::Package:: *)

at the start of the file. This interferes with the shebang line that designates a source file as an executable and prevents scripts from working.

I then fix this problem by closing all source files in mathematica and manually removing the line in a text editor - so this is more of an annoyance than an actual problem.

Does anyone know how the line addition can be prevented?


share|improve this question
Somehow I feel @John Fultz should be able to help here... –  Yves Klett Jul 9 '13 at 15:48
When I open a text file with a .m suffix and a shebang line in Mathematica, it evaluates it as the expression -script + #1!/(Applications Contents MacOS MathematicaScript Mathematica.app)! So you'd have to remove the shebang line to be able to edit the file again in Mathematica... –  cormullion Jul 9 '13 at 17:05

1 Answer 1

My advice is don't save your script as a .m file. Consider the following quote from the Mathematica documentation on scripts.

The Mathematica script does not need to have the .m extension. An executable script is a full-featured program equivalent to any other program in a Unix operating system, so it can be used in other scripts, in pipes, subject to job control, etc. Each Mathematica script launches its own copy of the MathKernel, which does not share variables or definitions.

share|improve this answer

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.