WolframScript Tutorial

By Xah Lee. Date: . Last updated: .

This is a tutorial on using WolframScript to do typical linux shell scripting tasks, such as bash and PowerShell.

What is WolframScript

WolframScript is a command line interface to Wolfram Engine. It lets you run WolframLang code from a terminal.

Wolfram Engine comes with WolframScript bundled.

Download Wolfram Language Free

Run WolframScript in terminal

type wolframscript

WolframScript math 2021-10-22 FYBv
WolframScript math 2021-10-22

Exit WolframScript

Type Exit or Quit.

Run a WolframLang code

wolframscript -code "3+1"

Run a WolframLang file

wolframscript -file test.wls

Print Result

# run a file and print last expression
wolframscript -file test.wls -print

Print All

# run a file and print all expressions
wolframscript -file test.wls -print all

Get help for options

wolframscript -h

wolframscript

Here's a complete list:

-h or -help

Print help text.

-c WL or -code WL

Give Wolfram Language code to execute.

-f or -file PATH

Give a file containing Wolfram Language code to execute.

-a or -api URL|UUID

Use an API at the specified URL, or coming from a cloud or local object with the specified UUID. Provide arguments in the form 'key=value' following '-args'.

-fun or -function WL

Use a function whose arguments are the strings given using '-args' interpreted as the types given using '-signature'

-o or -cloud [CLOUDBASE]

Execute code in the cloud, using the specified cloud base. By default, cloud base is https://wolframcloud.com

-l or -local [KERNELPATH]

Execute code locally, using the specified path to the Wolfram Engine kernel. By default, KernelPath uses the most recent version of the Wolfram Language found on the local system.

-- ARGS...,-args ARGS...

Used with '-api' or '-function' to provide arguments.

-s or -signature TYPE...

Used with '-function' and '-args' to specify interpreter types for provided arguments.

-v or -verbose

Print additional information during execution.

-activate [KEY]

Activate the Wolfram Engine through the cloud or with a key.

-entitlement ID

Activate the Wolfram Engine using on-demand licensing with the given license entitlement ID.

-authenticate [ID PASS]

Authenticate with the cloud, specifying a particular Wolfram ID and password, and prompting if they are not given. Different authentication can be specified for different clouds.

-disconnect

Disconnect from the cloud, removing authentication information.

-configure [KEY=VAL...]

Configure WolframScript by specifying values for particular configuration variable keys. If no keys are given, this prints the current configuration.

-version

Print version of WolframScript.

-username USERNAME

Give username for authentication.

-password PASSWORD

Give password for authentication.

-permissionskey KEY

Give a permissions key used to authorize access to a cloud deployed API.

-k or -noverifypeer

Disable peer certificate verification when interacting with the cloud.

-timeout SECONDS [VALUE]

Specify the number of seconds to allow for execution. Return value if time is exceeded.

-charset ENCODING

Use encoding for output. Encodings can be None to output raw bytes, or any entry in $CharacterEncodings except "Unicode". The default is to infer the value from the terminal's language settings.

-format TYPE

Specify the format in which to give output. Any format understood by Export can be used.

-print [all]

When running a script, print the result from executing the last line of the script, or each line if all is given.

-linewise

Execute code on each line of standard input that is read.

-script ARGS...

Counterpart to wolfram -script, additionally sets up $ScriptCommandLine.

Xah Talk Show 2021-11-20 Bash vs PowerShell vs WolframLang

WolframLang: Shell Tasks