How do you access ARGV in Mathematica?

I would like to write command line scripts in Mathematica, but I cannot find the Argv[i_Integer] function Argv[i_Integer] . (FANTASTIC documents otherwise.)

+6
source share
3 answers

$CommandLine works for Mathematica, MathematicaScript, MathKernel and math.

args.ma:

 #!/usr/bin/env MathKernel -script Print[$CommandLine] 

Example:

 $ ./args.ma abc {"MathKernel", "-script", "./args.ma", "a", "b", "c"} 
+4
source

$ ScriptCommandLine seems to be the variable you will need for this, provided you use MathematicaScript for scripting . If you use math or MathKernel -script , this will be $ CommandLine .

Other relevant discussions: pretty old and one in the MMA toolkit .

+6
source

I like to pass things when using environment variables:

http://reference.wolfram.com/mathematica/ref/Environment.html

+1
source

Source: https://habr.com/ru/post/900561/


All Articles