Inherited from v1.0.0

sys module

Process-level information and control: identity (platform, version, arch, pid, hostname, user), command-line arguments, environment variables, working directory, and process termination.

import "sys" as sys;

print("bnl",   sys.version, "on", sys.platform, sys.arch);
print("pid:",  sys.pid());
print("user:", sys.username());
print("argv:", sys.argv());
print("cwd:",  sys.cwd());

Constants

NameDescription
sys.platform"windows", "linux", "darwin", …
sys.versionbnl interpreter version string.
sys.archCPU architecture: "x86_64", "arm64", "x86", "arm", or "unknown".

Command-line arguments

FunctionDescription
sys.argc() → numberCount of args passed after the script path.
sys.arg(i) → string | nullThe i-th argument (0-indexed), or null if out of range.
sys.argv() → listAll CLI args as a list of strings.

Environment variables

FunctionDescription
sys.env(name) → string | nullLook up one environment variable.
sys.setenv(name, value) → nullSet or overwrite an env var. Throws if name is empty or contains =.
sys.unsetenv(name) → nullRemove an env var. No-op if it doesn't exist.
sys.envs() → mapSnapshot of every environment variable as a {KEY: value} map.

Process control

FunctionDescription
sys.exit(code)Terminate with the given exit code. Runs atexit handlers.
sys.abort()Abnormal termination — no atexit handlers; dumps core on Unix. Use for "unrecoverable" cases where exit would be misleading.

Process & host info

FunctionDescription
sys.pid() → numberCurrent process id.
sys.cpu_count() → numberNumber of logical CPUs, or 0 if unknown.
sys.hostname() → stringMachine hostname.
sys.username() → string | nullCurrent user name, or null if unknown.
sys.home() → string | nullUser home directory ($HOME on Unix, %USERPROFILE% on Windows), or null if unset.
sys.executable() → stringFull path to the running bnl interpreter binary.
sys.script() → string | nullPath of the entry .bnl script, or null for REPL / -e inline code.

Paths

FunctionDescription
sys.cwd() → stringCurrent working directory. UTF-8 on every OS.
sys.chdir(path) → nullChange the working directory. Throws if the path is invalid.
sys.tempdir() → stringOS temp directory (%TEMP% / /tmp / $TMPDIR).

See also

  • cli — declarative CLI argument parsing on top of sys.argv / sys.arg.
  • dotenv — read .env files into env-style maps.
  • path — manipulate the strings returned by sys.cwd / sys.executable / sys.script.