<a id="hsh"></a>

<a id="script-interpreter"></a>

# Script interpreter

The *hsh* program is a Halon [script](https://docs.halon.io/hsl/archive/6.12-stable/) interpreter and interactive shell (REPL).
It allows you to easily write, run and test Halon [script](https://docs.halon.io/hsl/archive/6.12-stable/)
without having to deploy it into the `smtpd` server.
It implements the full [standard library](https://docs.halon.io/hsl/archive/6.12-stable/functions.html), but not any *smtpd* server or queue hooks.
It also doesn’t provide an interface for *halonctl*’s [script](cli_script.html.md#halonctl-script)
commands.

<a id="options"></a>

## Options

<a id="cmdoption-hsh-c"></a>

<a id="cmdoption-hsh-config"></a>

### -c, --config path

In order to make the *hsh* script environment resemble the environment of *smtpd*,
it supports loading *smtpd*’s [startup configuration](config_startup.html.md) file
(default  */etc/halon/smtpd.yaml*) which in turn load the [running configuration](config_smtpd.html.md).
This allows all paths and permission to be set up correctly, as well as virtual files [`scripting.files[]`](config_smtpd.html.md#confval-scripting.files)
and certificates [`pki.private[]`](config_startup.html.md#confval-pki.private).
Since that file usually drop privileges and change user, it might require *hsh -P* to be run as root.
If you don’t need the full environment, you may run without a startup configuration:  */dev/null*.

<a id="cmdoption-hsh-P"></a>

<a id="cmdoption-hsh-privdrop"></a>

### -P, --privdrop

Drop privileges (setuid / setgid) to the user specified in the startup configuration.
This may allow you to have access to various sockets, but requires root permission.
The recommended setup would be to have shared group permission with the smtpd server on various sockets and paths.

<a id="cmdoption-hsh-F"></a>

<a id="cmdoption-hsh-ffi"></a>

### -F, --ffi

Enable [FFI](https://docs.halon.io/hsl/archive/6.12-stable/functions.html#ffi) support,
which is equivalent to [`scripting.ffi`](config_startup.html.md#confval-scripting.ffi),
without having to use [`hsh -c`](#cmdoption-hsh-c) to load a startup a configuration.

<a id="cmdoption-hsh-p"></a>

<a id="cmdoption-hsh-plugin"></a>

### -p, --plugin id

Load a specific HSL plugin. This option is repeatable.

<a id="cmdoption-hsh-R"></a>

<a id="cmdoption-hsh-rootpath"></a>

### -R, --rootpath path

Set the script root path,
which is equivalent to [`scripting.rootpath`](config_startup.html.md#confval-scripting.rootpath),
without having to use [`hsh -c`](#cmdoption-hsh-c) to load a startup a configuration.

<a id="cmdoption-hsh-A"></a>

<a id="cmdoption-hsh-appconf"></a>

### -A, --appconf path

Load a specific [running configuration](config_smtpd.html.md)
which is equivalent to [`environment.appconf`](config_startup.html.md#confval-environment.appconf),
without having to use [`hsh -c`](#cmdoption-hsh-c) to load a startup a configuration.

<a id="cmdoption-hsh-B"></a>

<a id="cmdoption-hsh-binary"></a>

### -B, --binary

Print output as binary (not as UTF-8), and also the
output of `echo` will not automatically include a newline (`\n`).

<a id="cmdoption-hsh-s"></a>

<a id="cmdoption-hsh-syntax"></a>

### -s, --syntax

Check the script syntax only.

<a id="cmdoption-hsh-v"></a>

<a id="cmdoption-hsh-version"></a>

### -v, --version

Display Halon version and exit.

<a id="id1"></a>

## Script interpreter

The *hsh* program may be executed with a script file as the entry point for the script execution.
It should be given as the last argument to the hsh command line.

```console
$ cat test.hsl
echo "Hello World";
$ hsh test.hsl
Hello World
```

Setting the root to the current directory may be useful when implementing unit testing of modules:

```console
$ cat module.hsl
function foo() {
   echo "Hello World";
}
$ cat test.hsl
import { foo } from "file://module.hsl";
foo();
$ hsh -R . test.hsl
Hello World
```

<a id="interactive-shell"></a>

## Interactive shell

The *hsh* program may be executed without a file, in which case it enters the interactive shell mode (REPL).
Statements are executed line-by-line.

```console
$ hsh
HSH> echo "Hello World";
Hello World
HSH>
```
