3
$\begingroup$

In order to avoid script-defined command-line arguments clashing with existing arguments to wolframscript, it appears you are supposed to use the -- (or equivalently -args). This works exactly as expected with the -code option:

> wolframscript -c 'Print[$ScriptCommandLine]' -- -foo 7 -bar 8 -baz 9

{wolframscript, -c, Print[$ScriptCommandLine], --, -foo, 7, -bar, 8, -baz, 9}
Null

Now let's create a file that does the same thing.

> echo 'Print[$ScriptCommandLine]' > test.m

> wolframscript -f test.m -- -foo 7 -bar 8 -baz 9
{test.m}

There's no trailing Null, which seems helpful, but all the arguments also vanish, which is not helpful.

FWIW, this seems to suffice as a workaround, but it's a pretty annoying one:

> wolframscript -c 'Get["test.m"]' -- -foo 7 -bar 8 -baz 9
{wolframscript, -c, Get["test.m"], --, -foo, 7, -bar, 8, -baz, 9}
Null

All of this is with Mathematica 11.3.0 on Mac OS X.

$\endgroup$
  • $\begingroup$ wolfram -script test.m -- -foo 7 -bar 8 -baz 9 $\endgroup$ – LouisB Nov 2 '18 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.