Skip to content

Class ShellEnvironment

Source: shellEnvironment.ts

Manages environment variabels for Shell.

Constructors

Constructor

new ShellEnvironment(initialVars: Record<string, string>, parent: ShellEnvironment | null): ShellEnvironment

Parameters

initialVars

Record<string, string> = {}

parent

ShellEnvironment | null

Returns

ShellEnvironment

Properties

store

store: Record<string, string> = {}


parent

parent: ShellEnvironment | null = null


exportedKeys

exportedKeys: Set<string>


USER

readonly static USER: "USER" = "USER"


HOSTNAME

readonly static HOSTNAME: "HOSTNAME" = "HOSTNAME"


WORKING_DIRECTORY

readonly static WORKING_DIRECTORY: "PWD" = "PWD"


PREVIOUS_WORKING_DIRECTORY

readonly static PREVIOUS_WORKING_DIRECTORY: "OLDPWD" = "OLDPWD"


EXIT_CODE

readonly static EXIT_CODE: "?" = "?"


ARGUMENT_COUNT

readonly static ARGUMENT_COUNT: "#" = "#"


PROCESS_ID

readonly static PROCESS_ID: "$" = "$"


INTERNAL_VARS

readonly static INTERNAL_VARS: string[]

List of variables that should never be exported.

Methods

get()

get(key: string): string | undefined

Parameters

key

string

Returns

string | undefined


set()

set(key: string, value: string, isExported: boolean): void

Parameters

key

string

value

string

isExported

boolean = false

Returns

void


export()

export(key: string): void

Marks an existing variable as exported.

Parameters

key

string

Returns

void


expand()

expand(input: string): string

Replaces variable placeholders in a string with their corresponding values.

Parameters

input

string

Returns

string


parseAssignment()

parseAssignment(input: string): boolean

Parses an assignment string (e.g., KEY=VALUE) and updates the environment.

Parameters

input

string

Returns

boolean

true if the string was a valid assignment.


fork()

fork(): ShellEnvironment

Creates a child scope for subshells or command execution.

Returns

ShellEnvironment

Accessors

exportedVariables

Get Signature

get exportedVariables(): Record<string, string>

Returns only variables that are marked for export.

Returns

Record<string, string>


variables

Get Signature

get variables(): Record<string, string>

Returns all variables visible to this scope (including internal).

Returns

Record<string, string>

Built by Prozilla