The os module provides operating-system information and services, including environment access, process execution, and filesystem operations.

os.name

attribute os

Signature

os.name

Description

The basic name of the operating system Teascript is being ran on.

The currently available name strings are:

  • windows
  • linux
  • osx
  • bsd
  • posix
  • browser
  • other

Example

import os

print("Operating system:", os.name)

os.arch

attribute os

Signature

os.arch

Description

The architecture of the operating system Teascript is being ran on.

The currently available name strings are:

  • x86
  • x64
  • arm
  • arm64
  • wasm

Example

import os

print("Architecture:", os.arch)

os.env

attribute os

Signature

os.env

Description

A map containing all environment variables and their values.

Example

import os

// Access a specific environment variable
print("Home directory:", os.env["HOME"])

// Iterate over all environment variables
for const key, value in os.env
{
    print(key + " = " + value)
}

os.getenv

function os

Signature

function os.getenv(name, def=nil)

Description

The function getenv retrieves the value of an environment variable.

Parameters

name
The name of the environment variable
def
(Optional) The value to use if the environment variable does not exist

Example

import os

// Get an environment variable
var path = os.getenv("PATH")
print("PATH:", path)

// Get with a default value
var config = os.getenv("APP_CONFIG", "default.json")
print("Config:", config)

os.setenv

function os

Signature

function os.setenv(name, value)

Description

The function setenv sets or unsets an environment variable.

Parameters

name
The name of the environment variable
value
The value to set, or nil to unset the variable

Example

import os

// Set an environment variable
os.setenv("MY_VAR", "hello")
print(os.getenv("MY_VAR"))  // hello

// Unset an environment variable
os.setenv("MY_VAR", nil)
print(os.getenv("MY_VAR"))  // nil

os.execute

function os

Signature

function os.execute(command)

Description

The function execute runs a shell command.

Parameters

command
The command to execute

Example

import os

// Execute a shell command
var status = os.execute("ls -la")
print("Command exited with status:", status)

os.remove

function os

Signature

function os.remove(filename)

Description

The function remove deletes a file.

Parameters

filename
The path to the file to delete

Example

import os

// Remove a file
var success = os.remove("temp.txt")
if success
{
    print("File deleted successfully")
}
else
{
    print("Failed to delete file")
}

os.rename

function os

Signature

function os.rename(fromname, toname)

Description

The function rename renames or moves a file.

Parameters

fromname
The current path of the file
toname
The new path of the file

Example

import os

// Rename a file
var success = os.rename("old.txt", "new.txt")
if success
{
    print("File renamed successfully")
}
else
{
    print("Failed to rename file")
}

os.mkdir

function os

Signature

function os.mkdir(dir)

Description

The function mkdir creates a new directory.

Parameters

dir
The path of the directory to create

Example

import os

// Create a new directory
os.mkdir("new_folder")
print("Directory created")