# How to recover WolframScript's former -run functionality?

With the 10.4 version of WolframScript, I could run something like

$WolframScript -run <CODE> -script /path/to/script.wl [ARGS...]  ...where <CODE> stands for some arbitrary WL expression. The command above would evaluate <CODE>, and then run /path/to/script.wl. This functionality was broken with version 11. For example, if simple_script.wl consists of a single line: Echo[First @$Path];


...then, with version 10.4 I get results consistent with the description given earlier, namely:

$WolframScript -run '$Path=DeleteDuplicates @ Prepend[$Path, "/my/mma/lib"];' \ -script simple_script.wl >> /my/mma/lib  ...but with version 11.1, the same command-line above results in Wolfram Language 11.1.0 Engine for Linux x86 (64-bit) Copyright 1988-2017 Wolfram Research, Inc. ToExpression::sntx: Invalid syntax in or before "= ". ^ In[1]:= Quit sh: 1: -script: not found  I.e., with version 11.1, the command-line above 1. runs into a syntax error (who knows why); 2. starts an interactive session (in text-mode); 3. never executes simple_script.wl; in fact, there appears to be an attempt (by what?) to execute, as a subsequent shell command, the tail of the original command-line starting with -script. This loss of functionality breaks a couple dozen analysis pipelines (many man-months worth of work), so I'd like to find a reasonable work-around that does not require retooling all this code. Is there a way to recover the functionality described above with version 11.1 of WolframScript? P.S. I'm aware of the new -code flag, but the latest version of WolframScript recognizes only the first of -code and -script it finds on the command-line, not both. • Apparently -run option is no longer supported in WolframScript, I will report it as suggestion to wolframscript team to consider it supporting in near future versions. Jul 2, 2017 at 4:36 ## 1 Answer This is an execution mode I don't think we encountered in internal testing for the new wolframscript, the thought being that such processing would occur early in the script, an any needed values would be passed in as arguments. I'm not 100% sure what's happening here--I should think that it would fall back to legacy mode and support this. @dsingh has already filed a bug, and I'll let the relevant developer investigate and see if we can fix it. Here are some workarounds. Instead of calling WolframScript, just call wolfram. If you don't access$ScriptCommandLine, just replacing WolframScript with wolfram will do everything you need:

wolfram -run '$Path=DeleteDuplicates @ Prepend[$Path, "/my/mma/lib"];' \
-script simple_script.wl


If you do access $ScriptCommandLine, you'll need to simulate it by inserting a double dash and repeating the script name after it, like this: wolfram -run '$Path=DeleteDuplicates @ Prepend[$Path, "/my/mma/lib"];' \ -script simple_script.wl -- simple_script.wl ARG1 ARG2 ...  If you still have Mathematica 10.4 installed you can use its version of WolframScript with 11.1. Copy 10.4's version of WolframScript, found in$InstallationDirectory/SystemFiles/Kernel/Binaries/Linux-x86-64, to the corresponding directory in your 11.1 install. If you now use this version of WolframScript (by using the full path or creating a symbolic link) it will behave exactly as in previous versions.

• Thanks! Regarding "...any needed values would be passed in as arguments", keep in mind that, in the Unix world, environment variables are a time-honored second way to pass values to programs. In fact, as the example I gave may hint at, we've been using the -run flag to support a functionality that is supported by pretty much every other scripting platform out there, namely an environment variable that specifies directories to be added to the search path for modules. ...
– kjo
Jul 5, 2017 at 12:51
• ... E.g. for Python, it's PYTHONPATH; for Perl, it's PERL5LIB; for MATLAB, it's MATLABPATH; etc. If WolframScript supports such an environment variable, please let me know.
– kjo
Jul 5, 2017 at 12:51
• Off the top of my head, I don't think we have such a thing, but this doesn't have to be done inside of -run. You can use GetEnvironment[] inside the script to get it. Or, if you want all scripts to look for a particular variable, add the following to /usr/share/Mathematica/Kernel/init.m: If[$ScriptCommandLine =!= {}, AppendTo[$Path, GetEnivronment[var]] Jul 7, 2017 at 23:59
• Certainly, but it is easier on our users for us to give them a wrapper script (around WolframScript, e.g.) that implements the desired behavior (through -run) than to ask them to modify their init.m files.
– kjo
Jul 10, 2017 at 11:45