Class ShellExperimental
Implements
- Shell
Index
Constructors
Properties
Accessors
Methods
Properties
Readonly Experimentalconfig
Shell configuration
Experimentalcredentials
Current user's credentials
Readonly Experimentalinterpreter
The shared statement walk. This shell supplies how a pipeline runs (see hostInterface).
Optional ExperimentalonExit
Called when exit runs at the prompt, so a login session ends instead of only setting $?.
Readonly Experimentalstate
The language state shared with /bin/ecmash: variables, arrays, local frames, readonly, functions, aliases,
traps and options. The underscore names below are views onto it.
Accessors
aliases
arrays
context
-
get context(): BoundContext
ExperimentalShell context
Returns BoundContext
-
set context(value: BoundContext): void
ExperimentalA new context starts with this shell's file creation mask, so a login or
suthat rebinds it does not loseumask.Parameters
- value: BoundContext
Returns void
cwd
-
get cwd(): string
ExperimentalCurrent working directory
Returns string
-
set cwd(path: string): void
ExperimentalSetting the working directory also sets
PWDandOLDPWD.Parameters
- path: string
Returns void
env
envObject
-
ExperimentalThis shell's environment as a plain object: the
envpof every child. Shell-internal names (seeSHELL_ONLY_VARIABLES) are left out.Returns Record<string, string>
foregroundJob
-
get foregroundJob(): Job | undefined
ExperimentalReturns Job | undefined
functions
-
ExperimentalRegistered
name() { ... }function bodies, keyed by nameReturns Map<string, Statement[]>
getoptsCharIndex
-
get getoptsCharIndex(): number
Experimentalgetopts's position within the argument it is currently reading. See _getoptsCharIndex.Returns number
-
set getoptsCharIndex(index: number): void
Experimentalgetopts's position within the argument it is currently reading, for clustered options like-abc.$OPTINDcounts arguments and cannot express that; assigningOPTIND=1resets this too.Parameters
- index: number
Returns void
i18n
-
get i18n(): I18n
ExperimentalTranslated strings, for the messages the shell itself prints.
Returns I18n
id
-
get id(): string
ExperimentalShell ID
Returns string
interrupted
-
get interrupted(): boolean
ExperimentalWhether the line currently running was interrupted by
^C.Returns boolean
positionalParameters
-
get positionalParameters(): string[]
Experimental$1,$2, ... in order, up to the first gap;$0is excluded.Returns string[]
process
-
get process(): Process
ExperimentalThis shell's own process; see
_process. Created lazily because/devis not mounted when the shell is constructed.Returns Process
shellOptions
-
get shellOptions(): ShellOptions
ExperimentalThe name of a
setflag; see ShellOptionState for what each one does.Returns ShellOptions
terminal
-
get terminal(): Terminal
ExperimentalTerminal
Returns Terminal
tty
-
get tty(): number
ExperimentalReturns number
umask
-
get umask(): number
ExperimentalThe file mode creation mask. The programs this shell starts take it, and so do the files it creates for a redirection; a file system with a mask of its own is given the same one.
Returns number
-
set umask(mask: number): void
ExperimentalParameters
- mask: number
Returns void
username
-
get username(): string
ExperimentalCurrent username
Returns string
users
-
get users(): Users
ExperimentalThe real user registry.
Returns Users
Methods
appendArray
-
ExperimentalAppends elements to an array (
a+=(...)), creating it if needed.Parameters
- name: string
- values: string[]
Returns void
applyShellOption
-
ExperimentalApply a
setflag. See _shellOptions for what each one does.Parameters
- flag: keyof ShellOptionState
- enabled: boolean
Returns void
attach
-
ExperimentalAttaches a terminal to the shell
Parameters
- terminal: Terminal
Returns void
bg
-
ExperimentalResumes a stopped job with
SIGCONTin the background, without waiting for it.Parameters
Optionalspec: string
Returns Job | undefined
claimInterrupt
-
ExperimentalTrue for the first caller after an interrupt, false for the rest, so an interrupted pipeline reports once rather than once per stage. Cleared when the next command starts.
Returns boolean
claimProcessEnv
-
ExperimentalMakes this shell the one
globalThis.process.envmirrors. Called when its TTY becomes active.Returns void
clearPositionalParameters
-
ExperimentalClears positional parameters
Returns void
declareLocal
-
ExperimentalDeclare
nameas local to the current function call, defaulting to '' until assigned.Parameters
- name: string
Optionalvalue: string
Returns void
deliverSignal
-
ExperimentalDelivers a signal sent to this shell with
kill: runs the trap for it, if any. False when there is no trap.Parameters
- signal: number
Returns Promise<boolean>
describeCommand
-
describeCommand(
name: string,
): Promise<
| {
kind: "function"
| "file"
| "alias"
| "keyword"
| "builtin";
path?: string;
}
| undefined,
>ExperimentalHow a command name resolves, for
typeandcommand -v: alias, keyword, builtin, function or$PATHfile, in that order.Parameters
- name: string
Returns Promise<
| {
kind: "function"
| "file"
| "alias"
| "keyword"
| "builtin";
path?: string;
}
| undefined,
>
diagnosticPrefix
-
ExperimentalWhat the shell's own messages start with:
ecmaos:, or./script: line N:while a script file runs, as bash does.Returns string
execute
-
ExperimentalExecutes a line typed at the prompt. Lines with control flow go through
parseStatementsandexecuteStatements; a line that does not parse is a syntax error (status 2) and runs nothing.Parameters
- line: string
Returns Promise<number>
executeScriptText
-
ExperimentalRuns a full script's text to completion; the entry point of
Kernel.runScriptFile.Parameters
- script: string
Optionalfile: stringOptionalargs: string[]
Returns Promise<number>
executeSourced
-
ExperimentalRuns
textin this shell (source,eval): variables, functions andcdpersist. TheEXITtrap does not run,returnis caught, andexitis not.positionalreplaces$1..for the duration.Parameters
- text: string
Optionalpositional: string[]Optionalfile: string
Returns Promise<number>
executeStatements
-
ExperimentalRuns a statement tree: plain lines through
execute(), control-flow nodes interpreted here.break,continue,returnandexitare builtins that throw signals caught by the nearest loop,callFunctionorexecuteScriptText.Parameters
- statements: Statement[]
Returns Promise<number>
expandTilde
-
ExperimentalExpands
~,~/and~/pathto the user's home, outside single quotes.Parameters
- input: string
Returns string
expansionContext
-
ExperimentalBuilds the
ExpansionContextbound to this shell's variables, arrays and positional parameters.Returns ExpansionContext
fg
-
ExperimentalResumes a stopped job with
SIGCONT, or brings a background job to the foreground, and waits for it.Parameters
Optionalspec: string
Returns Promise<number | undefined>
getJob
-
ExperimentalResolves a job spec:
%N,%%/%+,%-, a pid, or none (the current job). Undefined if nothing matches.Parameters
Optionalspec: string
Returns Job | undefined
getTrap
-
ExperimentalThe handler registered for
signal, if any.Parameters
- signal: string
Returns string | undefined
hasPromptCommand
-
ExperimentalTrue when
PROMPT_COMMANDhas something to run, so the prompt can skip the async hop when it does not.Returns boolean
isReadonly
-
ExperimentalWhether
namewas markedreadonly, so an assignment or an unset must be refused.Parameters
- name: string
Returns boolean
listJobs
-
ExperimentalAll tracked jobs, oldest first. See
_jobs's doc comment for retention behavior.Returns Job[]
listTraps
-
ExperimentalEvery registered trap as
[signal, handler]pairs, for baretrap's listing.Returns [string, string][]
loadConfig
-
ExperimentalLoads terminal configuration from config files and applies to terminal
Returns Promise<void>
loadEnvFile
loadProfile
-
ExperimentalRuns the startup files in the order given by
shell-core/startup-files. Does not fire theEXITtrap, and a file that fails does not stop the others.Returns Promise<void>
lookupArray
-
ExperimentalReads
name's array from the innermost frame that declares it, else from the shell's own.Parameters
- name: string
Returns Map<string | number, string> | undefined
lookupVariable
-
ExperimentalResolves a variable: the innermost
localframe first, then the environment.Parameters
- name: string
Returns string | undefined
markReadonly
-
ExperimentalMarks
namereadonly. There is deliberately no way back, as in bash.Parameters
- name: string
Returns void
notifyInterrupted
-
ExperimentalReturns Promise<void>
ownsPid
-
ExperimentalWhether
pidis this shell's own process, the one$$names.Parameters
- pid: number
Returns boolean
parseEnvFile
-
ExperimentalParses environment variables from a string
Parameters
- content: string
Returns Record<string, string>
publishEnv
-
ExperimentalPublishes the exported environment to
globalThis.process.envif this shell owns that mirror; a no-op otherwise.Returns void
readonlyNames
-
ExperimentalEvery readonly name, for
readonly -p.Returns string[]
recordLogin
-
ExperimentalFiles this console's login in
/run/utmpand/var/log/wtmp. A failure to record is never a failure to log in.Parameters
- username: string
Returns Promise<void>
recordLogout
-
ExperimentalReturns Promise<void>
removeJob
-
ExperimentalForgets a job without touching its processes (
disown): no morejobsentry and no Done notice.Parameters
- job: Job
Returns void
runPromptCommand
runTrap
-
ExperimentalRuns the handler registered for
signal, if any (and it isn't the''ignore marker). Errors from the handler are swallowed - a bad trap must not crash the shell.Parameters
- signal: string
Returns Promise<void>
setArray
-
ExperimentalReplaces an array's entire contents.
Parameters
- name: string
- values: string[]
Returns void
setArrayElement
-
ExperimentalSets one array element by index, creating the array if needed.
Parameters
- name: string
- index: number
- value: string
Returns void
setPositionalParameters
-
ExperimentalSets positional parameters
Parameters
- args: string[]
Returns void
setTrap
-
ExperimentalSets, clears or ignores a trap. Names are normalized (
SIGINTandINTare the same).Parameters
- handler: string | undefined
- signal: string
Returns void
setVariable
takeJobNotifications
-
ExperimentalNotices for finished background jobs, polled at prompt time. Reporting retires the job.
Returns string[]
unsetArray
-
ExperimentalRemoves an entire array (
unset a).Parameters
- name: string
Returns void
unsetArrayElement
-
ExperimentalRemoves one array element by index (
unset a[i]).Parameters
- name: string
- index: number
Returns void
visibleVariables
-
ExperimentalEvery variable visible now,
localframes over the environment, without shell-internal names. Whatexport -pand bareenvlist.Returns Map<string, string>
wait
-
ExperimentalWaits for one job or pid, or for every running or stopped background job when called with none.
Parameters
Optionalspec: string
Returns Promise<number | undefined>
Author
Jay Mathis code@mathis.network (https://github.com/mathiscode)
The Shell class handles the Terminal environment and interaction with the Kernel.