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> = {}


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"


HOME ​

readonly static HOME: "HOME" = "HOME"


PROMPT ​

readonly static PROMPT: "PS1" = "PS1"


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[]

Array 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(node: ParameterExpansionNode, expandedArgument?: string): string

Replaces variable placeholders in a string with their corresponding values based on a pre-parsed node. The expandedArgument must be pre-resolved by the interpreter to handle nested expansions.

Parameters ​

node ​

ParameterExpansionNode

expandedArgument? ​

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.


setCommandArguments() ​

setCommandArguments(commandName: string, args: string[]): void

Parameters ​

commandName ​

string

args ​

string[]

Returns ​

void


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