Skip to content

sys

the world outside zil: script arguments, environment variables, other programs, opening files, the clipboard, and the web

Permissions: env, processes, open, network, clipboard, exit

Reaches outside zil: the arguments a script was given, environment variables, other programs, files and links to open, the clipboard and web requests. What a host allows is controlled by its permissions.

Tags: files, network

  • args the command-line arguments given after the script’s name (or after -e code), as a list of strings: for zil script.zil a b, that’s [“a”, “b”]
  • env the value of an environment variable, or nil if it isn’t set
  • exit stop the script now, with an exit code for whatever ran it
  • sh run a command line through the system shell (sh, or cmd on Windows) and return what it printed, without the final newline
  • exec run a program directly, without a shell, given as a list of its name and arguments
  • run run a command line through the system shell and return {code, out, err}: its exit code, output and error output
  • open open a file or folder with the system’s default program, and return its path
  • copy copy a value to the clipboard, as print would show it, and return it
  • paste the text on the clipboard
  • fetch download a URL and return its content as a string
args() -> list

the command-line arguments given after the script’s name (or after -e code), as a list of strings: for zil script.zil a b, that’s [“a”, “b”]

1
args()[]
Example outputCtrl+Enter to run

See also env

env() -> map / env(name: str) -> str|nil

the value of an environment variable, or nil if it isn’t set

With no name, all of them as a map

1
env("ZIL_SURELY_UNSET")nil
Example outputCtrl+Enter to run

See also args

exit(code: int = 0) -> nil

stop the script now, with an exit code for whatever ran it

0 means success, anything else failure

1
exit(1)
Example outputCtrl+Enter to run

See also args

sh(cmd: str) -> str

run a command line through the system shell (sh, or cmd on Windows) and return what it printed, without the final newline

An error if the command fails

1
sh("git rev-parse --short HEAD")
2
sh("ls").lines.len
Example outputCtrl+Enter to run

See also run

exec(argv: list, *more: list, stdin?: any, stderr?: str, tty: bool = false) -> str|bytes|int

run a program directly, without a shell, given as a list of its name and arguments

With several lists, each one’s output is piped into the next. Returns what the last printed, without the final newline (as bytes if it isn’t text), and is an error if one fails. !prog args turns into a call to exec

  • stdin a value to feed the first program as input
  • stderr a file to send error output to
  • tty show the output in the terminal and return the exit code instead
1
exec(["git", "log", "--oneline"], ["head", "-3"])
2
!objdump -d a.out | grep call
Example outputCtrl+Enter to run

See also sh, open

run(cmd: str) -> map

run a command line through the system shell and return {code, out, err}: its exit code, output and error output

Never an error just because the command failed

1
run("git status").code
Example outputCtrl+Enter to run

See also sh

open(path: str) -> str

open a file or folder with the system’s default program, and return its path

1
open("report.pdf")
Example outputCtrl+Enter to run

See also exec

copy(v: any) -> any

copy a value to the clipboard, as print would show it, and return it

1
sh("git rev-parse HEAD") |> copy
Example outputCtrl+Enter to run

See also paste

paste() -> str

the text on the clipboard

1
paste().lines.len
Example outputCtrl+Enter to run

See also copy

fetch(url: str) -> str

download a URL and return its content as a string

An error if the server answers with an error status

1
fetch("https://api.github.com/repos/rust-lang/rust").from_json.stargazers_count
Example outputCtrl+Enter to run

See also from_json

1
# arguments after the script
2
args()[]
3
# is a variable set?
4
env("ZIL_SURELY_UNSET") == niltrue
5
# are any environment variables set?
6
env().len > 0true
Example outputCtrl+Enter to run

Example results generated on 2026-11-04. Ones using now, today or randomness will differ when you run them.