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?

Thanks!

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
    
Not only does it add that line, it also mangles all non-ASCII characters. If you have e.g. (* :Author: Pál *), it'll change to (* :Author: P[\AAcute]l *), which is very annoying. For these reasons I try to avoid using the front end to edit .m files. –  Szabolcs Apr 17 at 2:23

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.

Update

To reply to the question raised by bobthechemist in a comment, there appears to be no difference at all between a .m file and a .wl file created with Mathematica's Package style. Here is image of a short .wl file I created and use regularly.

FUAPatterns

share|improve this answer
    
I now have this same question. Has there been any solutions? –  tarhawk Apr 17 at 0:26
    
@tarhawk. I have repaired the link that broke in my answer. I recommend that you should follow it and read the full article on Wolfram Language Scripts. –  m_goldberg Apr 17 at 2:01
    
Does anyone know if the same behavior is observed with the .wl extension that seems to be the "new kind of extension"? –  bobthechemist Apr 17 at 2:50

Your Answer

 
discard

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.