如果在foo.m中有Mathematica代码,Mathematica可以用-noprompt
和-initfile foo.m
(或-run "<<foo.m"
)调用,并且命令行参数可用$CommandLine
(在那里有额外的垃圾)但是有没有办法让一些mathematica代码像
#!/usr/bin/env MathKernel
x = 2+2;
Print[x];
Print["There were ", Length[ARGV], " args passed in on the command line."];
linesFromStdin = readList[];
etc.
Run Code Online (Sandbox Code Playgroud)
和chmod它可执行并运行它?换句话说,如何像任何其他脚本语言(Perl,Python,Ruby等)一样使用Mathematica?