How do you pass negative values as input for a
This documentation page explains that the syntax for passing parameters is:
wolframscript -file filename.m 1 2 3 output.txt
However it seems it doesn't work with negative parameters, since, for example, the
wolframscript -file filename.m 1 -2 3 output.txt
is interpreted as an option, not as a number/parameter and the script returns an error saying that:
Export::infer: Cannot infer format of file 1.
As MWE take for example the script:
arg=ToExpression/@Most@Rest[$ScriptCommandLine]; (*Drop first argument (which is filename.m by default) and last argument and transforms strings to numbers*) file=Last[$ScriptCommandLine]; (*The last argument is the output file name*) Export[file,arg]; (*Exports*)
This is generated from a .nb by saving it as .m file with shift+ctrl+s after selecting all the cells and pressing ctrl+8.
EDIT After the answer by @Syed, I see I have to add that I use Ubuntu. With Syed's answer I get the error:
./run.sh: line 3: syntax error near unexpected token `('.
The full bash script
#! /bin/bash wolframscript -file filename.m 1 (-2) 3 output.txt