Run Wolfram Language Code from the Command Line
Use the Wolfram Language in a command-line interface with the WolframScript command-line script interpreter.
With Code in the Command Line...
Run Wolfram Language code directly in a command-line interface with the WolframScript -code option:
With Code from a File...
Create a file of Wolfram Language code:
Run the code in the file:
- Use Print to produce an output from code in a file. The value of the last expression in a file is not returned by default, as in the notebook interface.
- If the code in a file does not explicitly print a result, you can nevertheless cause the last output to be printed with the WolframScript -print option.
With Execution in the Wolfram Cloud...
If you do not have a local installation of the Wolfram System, you can still run Wolfram Language code from the command line in the Wolfram Cloud:
- If you are not already logged into the Wolfram Cloud, the first time you run WolframScript in the cloud, you will be asked to authenticate. Subsequent invocations of WolframScript will not require you to authenticate again.
- If there is no local installation of the Wolfram System, WolframScript will automatically execute in the Wolfram Cloud.
WolframScript is installed by default along with the Wolfram System on Windows and Linux. On Mac, you must run the “Extras” installer bundled with the Wolfram System to obtain WolframScript.
Visit the WolframScript page to download and install the latest version of WolframScript.
Characters that have special meaning to a command-line interface may require escaping or quotes when they are used in Wolfram Language code.
This code does not work as expected because of the special meaning of braces in the bash shell:
Fix the code by escaping the braces:
Or enclose the code in quotes:
- In bash and other Unix shells, single quotes disable all special characters, including $ and `.
- On Windows, disable special characters by wrapping command-line arguments with double quotation marks.
Each invocation of WolframScript runs in its own kernel session. Definitions do not persist from one invocation to the next: