Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

sys

script arguments, environment variables, shell commands, HTTP GET

Example results generated on 2026-10-08. Ones using now, today or randomness will differ when you run them: press Run on any example to run it in your browser, after editing it if you like.

scripts

# zil script.zil a b  →  args() is ["a", "b"]
# sh fails on a non-zero exit; run never does
# currency rates and translation stay offline until allow_network_access()

Functions

functiondescription
args()command-line arguments after the script (or after -e code), as strings
env() / env(name: str)an environment variable, or nil; with no name, all of them as a map
exit(code?: int)stop the program with an exit code (default 0)
sh(cmd: str)run a shell command (sh -c, or cmd /C on Windows) and return its output, trailing newline trimmed; errors on a non-zero exit
run(cmd: str)run a shell command and return {code, out, err}; never fails on the exit code
fetch(url: str)HTTP GET a URL and return the body as a string; errors on a non-2xx status
allow_network_access()let currency rates and translation go online for the rest of the session; until then they only use cached data

args

args(): command-line arguments after the script (or after -e code), as strings

args()
# → []

See also: env

env

env() / env(name: str): an environment variable, or nil; with no name, all of them as a map

env("ZIL_SURELY_UNSET")
# → nil

See also: args

exit

exit(code?: int): stop the program with an exit code (default 0)

exit(1)

See also: args

sh

sh(cmd: str): run a shell command (sh -c, or cmd /C on Windows) and return its output, trailing newline trimmed; errors on a non-zero exit

sh("git rev-parse --short HEAD")
sh("ls").lines.len

See also: run

run

run(cmd: str): run a shell command and return {code, out, err}; never fails on the exit code

run("git status").code

See also: sh

fetch

fetch(url: str): HTTP GET a URL and return the body as a string; errors on a non-2xx status

fetch("https://api.github.com/repos/rust-lang/rust").from_json.stargazers_count

See also: from_json

allow_network_access

allow_network_access(): let currency rates and translation go online for the rest of the session; until then they only use cached data

allow_network_access()

See also: fetch

More examples

sys

# arguments after the script
args()
# → []
# is a variable set?
env("ZIL_SURELY_UNSET") == nil
# → true
# how many env vars
env().len > 0
# → true