os

The computer TB runs on: your program's arguments, environment variables, running other programs, and exiting.

os.run needs the TB app on your computer. In the playground, os.platform is "browser".

import os

Example

import os

say(f"Running on: {os.platform}")
say(f"Arguments: {os.args}")
say(os.env("TB_EXAMPLE_SETTING", "not set"))

Functions

env(name, default?)

returns text

An environment variable, like env("HOME"), or default (nil) if it isn't set.

run(command, options?)

returns map

Run another program and wait for it. Gives back {"code", "out", "err"}: the exit code (0 means it worked) and what it printed. A text command goes through the system shell, so pipes and wildcards work: run("ls -l | head"). Never build that text from untrusted input. A list runs the program directly with exactly those arguments, with no shell: run(["ping", "-c", "1", host]). Prefer this whenever input comes from outside. options: {"timeout": seconds, "cwd": folder, "input": text to send it}. Not available in the browser playground.

quote(text)

returns text

Make text safe to put inside a shell command for os.run (mac/linux shells).

exit(code?)

Stop the program now. 0 (the default) means all went well.

Values

NameValueWhat it is
os.argsdepends on the computerThe words after the file name: tb main.tb a b gives ["a", "b"].
os.platformdepends on the computer"windows", "mac", "linux" or "browser".
os.userdepends on the computerThe name of the person logged in to this computer.
os.scriptdepends on the computerThe path of the running .tb file ("" in the REPL).