Use the Wolfram Language as the scripting language for shell scripts.

With Textual Output...

Create a script file

Choose File New Script to create a new script file. Type Wolfram Language code in the script:

  • Use Print to produce an output from a script. The value of the last expression in a script is not returned by default, as in the notebook interface.

Make the script executable

On Mac and Linux, set the script permissions to make it executable:

  • In Version 11.2 and higher of Wolfram Desktop, scripts created via File New Script are automatically executable.

Run the script

On Mac and Linux:

On Windows:

With Command-Line Arguments...

Create a script file

Use File New Script, as in the preceding section, to create a shell script that squares a numeric argument with Wolfram Language code. $ScriptCommandLine gives access to script arguments as strings:

  • Use Print to produce an output from a script. The value of the last expression in a script is not returned by default, as in the notebook interface.

Make the script executable

On Mac and Linux, set the script permissions to make it executable:

  • In Version 11.2 and higher of Wolfram Desktop, scripts created via File New Script are automatically executable.

Run the script

On Mac and Linux:

On Windows:

With Non-Text Output...

Create a script file

Create a shell script that makes a clock image showing the current time with Wolfram Language code. On Mac and Linux, the first line of the file must start with #!, followed by the path to the WolframScript executable. Specify an image output format with the -format option:

  • File New Script does not support adding options to the shebang line (the one starting with #!). Use any plain text editor to create the script file.
  • Output formats other than text are not supported on Windows.
  • Use Print to produce an output from a script. The value of the last expression in a script is not returned by default, as in the notebook interface.

Make the script executable

On Mac and Linux, set the script permissions to make it executable:

Run the script

On Mac and Linux:

View the output

Notes

On Windows, scripts must have the extension .wls to be recognized as Wolfram Language scripts. A first shebang line (one that starts with #!) is ignored if present. A script can be run from the Command prompt by typing its name:
Double-clicking a Wolfram Language script in Windows Explorer will launch it.
  • Within Unix-like environments on Windows such as cygwin, wolframscript scripts behave as in Linux, and require the shebang line.