【发布时间】:2011-12-19 20:01:58
【问题描述】:
我想在 Mathematica 中编写命令行脚本,但我似乎找不到类似 Argv[i_Integer] 的函数。 (否则文档非常棒。)
【问题讨论】:
标签: wolfram-mathematica command-line-arguments argv
我想在 Mathematica 中编写命令行脚本,但我似乎找不到类似 Argv[i_Integer] 的函数。 (否则文档非常棒。)
【问题讨论】:
标签: wolfram-mathematica command-line-arguments argv
似乎$ScriptCommandLine 是您需要的变量,假设您使用MathematicaScript 编写脚本。如果您使用math 或MathKernel -script,它将是$CommandLine。
其他相关讨论:rather old one 和 MMA 中的一个toolbag。
【讨论】:
MathKernel 将$ScriptCommandLine 报告为空{},无论提供的实际参数如何。和MathematicaScript 报告Could not find Mathematica installation directory.
【讨论】:
$CommandLine 适用于 Mathematica、MathematicaScript、MathKernel 和数学。
args.ma:
#!/usr/bin/env MathKernel -script
Print[$CommandLine]
例子:
$ ./args.ma a b c
{"MathKernel", "-script", "./args.ma", "a", "b", "c"}
【讨论】: