2
$\begingroup$

I have some scripts in ".nb" format and I am more used to launch them in Linux command line in Linux but I need them in ".m" format.

Usually I open the ".nb" script with the Mathematica Notebook and I can save it as ".m" script.

Is there any command line to perform this operation ?

$\endgroup$

marked as duplicate by Szabolcs, m_goldberg, Kuba Nov 25 '18 at 21:33

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • $\begingroup$ Why do you want to do it from a command line? A notebook can only be edited with the graphical interface. Why can't you convert it to a plain text format when you are finished editing it with the GUI? Or better: if you prefer the command line, why don't you write the .m file directly instead of the .nb? $\endgroup$ – Szabolcs Nov 16 '18 at 16:21
  • 1
    $\begingroup$ If you set the cells with code to initialization cells and set the AutoGeneratedPackage notebook option to True then every time you save you will get also an updated .m file $\endgroup$ – Gustavo Delfino Nov 16 '18 at 17:57
  • $\begingroup$ I need to do it because I need to execute a lot of .nb files that I didn't written (they are those of my students). And maybe later I would like to write a script to do the job. I would like to avoid to open the Mathematica editor, in that case a simple "save as " .m file answers my question. So apparently there is no solution without opening the mathematica notebook or modifying the .nb file. $\endgroup$ – Smilia Nov 17 '18 at 16:22
  • 1
    $\begingroup$ Of course there are possibilities to do this from the command line, the comments just tried to make clear that the problem could be solved easier with a solution different from what you have asked for. What would work is to write Mathematica code which builds a list of notebooks filenames, then for each of them opens it and calls the save as command programmatically. This would be easiest to write as a notebook and run from the mathematica frontend, but with some extra effort could be made to work from the command line. If you show some initial effort I am sure you will get any help needed... $\endgroup$ – Albert Retey Nov 18 '18 at 19:44
  • 1
    $\begingroup$ You also seem to simply want to automate things, which is something entirely different form runnings things on the command line. Which one do you want? $\endgroup$ – Szabolcs Nov 19 '18 at 18:23