Configuring scripts

Scripts in the State Tool can be compared to scripts in NPM, or build targets in a Makefile. You define a script and can then run it whenever you need to. Let’s start with something simple:

 - name: hello
   language: bash
   value: echo Hello World

This will register a script with the alias “hello”. You can run this outside your “activated state” via the state run command by running state run hello, but once you state activate it becomes much simpler, you simply invoke it by running hello.

NOTE: When creating new scripts or updating existing scripts, you should specify the language your script uses. Currently, if you do not specify a language you will get a deprecation warning, and the default shell for your operating system will be used. In the future, scripts will fail if no language is specified.

If you are using shell scripts on multiple platforms, you can use constraints to specify the shell to use on each operating system. For example, you could specify batch to run cmd.exe on Windows and bash to run bash on Linux and macOS.

If you want to use one single script for all platforms, you can configure your project on the ActiveState Platform to include a Python or Perl runtime, after which can define a script to use that language, for example:

  - name: hello
    language: python3
    value: print("Hello World")

The following language settings are supported:

bashFor scripts that use bash (Bourne again shell).
shFor script that use sh (Bourne shell).
batchFor scripts that use cmd.exe on Windows.
perlFor scripts that use your Perl runtime environment.
python2For scripts that use your Python 2 runtime environment.
python3For scripts that use your Python 3 runtime environment.

Support for specifying Tcl as the script language is not yet available.

See the section on Constraining Scripts for information on limiting language to the appropriate operating system. For example, only running batch scripts on Microsoft Windows.