I'd like to write command line scripts in Mathematica, but I can't seem to find an Argv[i_Integer]
like function. (The docs are FANTASTIC otherwise.)
It seems that $ScriptCommandLine is the variable you would need for this, assuming you're using MathematicaScript for scripting. If you use math
or MathKernel -script
it would be $CommandLine.
Other relevant discussions: a rather old one and one in the MMA toolbag.
$CommandLine
works for Mathematica, MathematicaScript, MathKernel, and math.
args.ma:
#!/usr/bin/env MathKernel -script
Print[$CommandLine]
Example:
$ ./args.ma a b c
{"MathKernel", "-script", "./args.ma", "a", "b", "c"}
I'm fond of passing things in using environment variables:
http://reference.wolfram.com/mathematica/ref/Environment.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With